我正在使用Tkinter获取用户的电子邮件地址,从电子邮件中读取图像,进行处理,然后希望在Tkinter画布中显示原始图像和处理后的图像,以及将处理后的图像发送回用户
以下是我的初始化和更新功能:
class App:
def __init__(self, window, window_title, video_source=0):
#create main Tkinter window
sys.setrecursionlimit(500)
self.finish = None
self.window = window
self.window.title(window_title)
self.video_source = video_source
window.resizable(0, 0)
labelText = tkinter.StringVar()
labelText.set ("")
labelDir= tkinter.Label(window, textvariable = labelText, height = 0)
labelDir.pack(side = "left")
self.e = tkinter.Entry(self.window)
self.e.pack()
self.w = tkinter.Label(window, text="Enter Your Email Address")
self.w.pack()
self.thisFrame1 = None
self.thisFrame2 = None
self.c = ttk.Combobox(window, values=["Candy", "Wave", "Composition",
"Feathers", "La_muse", "Mosaic",
"Starry", "Scream", "Udnie"])
self.c.pack()
self.l = tkinter.Label(window, text="Choose your style")
self.l.pack()
B1 = tkinter.Button(window, text="Send", command = self.close)
B1.pack()
def update(self):
#from PIL import Image, ImageTk
print("In update\n")
img = ImageTk.PhotoImage(Image.fromarray(self.finish)) # First and maybe second copy.
self.canvas = tkinter.Canvas(self.window, width = img.width(), height = img.height())
self.canvas.pack()
self.canvas.create_image(0, 0, image = img, anchor = tkinter.NW)
#img.show()
self.window.update_idletasks()
print("Finish update\n")
现在,调用update()的代码只有一部分在这里:
print('Sending Email ...')
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server:
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email, text)
print(' Email Sent')
# In[26]:
self.update()
画布将立即显示经过处理的图像(如瞬间),然后图像消失,后面留下空白画布。带有已处理图像的电子邮件已成功发送。
我尝试了各种其他方式来从我可以收集的所有在线帮助中更新画布,但无济于事。