@
ctro15547 #5 写完了
```
import pyperclip
import time
import requests
from PIL import Image
class Listen():
def isImgUrl(self, txt):
# 判断是否是 url
txt = str.strip(txt)
return txt[0:4] == 'http'
def downloadImg(self, url):
# 下载图片
res = requests.get(url)
with open("tmp.png", "wb") as code:
code.write(res.content)
def clipboard_get(self):
"""获取剪贴板数据"""
data = pyperclip.paste()
return data
def show_img(self):
# img = mpimg.imread('tmp.png')
# plt.imshow(img) # 显示图片
# plt.axis('off') # 不显示坐标轴
# plt.show()
im = Image.open('tmp.png')
im.show()
def main(self):
last_txt = ""
while True:
# txt 存放当前剪切板文本
txt = self.clipboard_get()
if last_txt != txt:
last_txt = txt
if self.isImgUrl(txt):
self.downloadImg(txt)
self.show_img()
time.sleep(0.5)
if __name__ == '__main__':
Listen().main()
```