我已经用Tkinter在Python中制作了一个小的Paint程序,现在我想添加一个“复制”功能,以便您可以在Discord等其他应用程序中更快地按CTRL + V绘制图形。这是一个测试:
def Copy():
def send_to_clipboard(clip_type, data):
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardData(clip_type, data)
win32clipboard.CloseClipboard()
x2 = fen.winfo_rootx()+Can.winfo_x()
y2 = fen.winfo_rooty()+Can.winfo_y()
x1 = x2+Can.winfo_width()
y1 = y2+Can.winfo_height()
print("save")
ImageGrab.grab().crop((x2,y2,x1,y1)).save("Image.bmp")
filepath = "Image.bmp"
image = Image.open(filepath)
output = io.BytesIO()
image.convert("RGB")
image.save(output, "BMP")
data = output.getvalue()[8:]
output.close()
send_to_clipboard(win32clipboard.CF_DIB, data)
当我尝试此操作时,除了不能将图像粘贴到“ Paint”或“ Discord”中外,它都起作用。 或它无法读取,或崩溃。 有谁可以帮助我吗? ;-;