我想使用filedialog.askopenfilename()从用户那里获得2张图像 并排显示在屏幕上,我可以读取图像,但是在GUI中图像没有显示
root = Tk()
root.geometry("%dx%d" % (400, 300))
root.title("BMP Image GUI")
canvas = Canvas(root)
def IdUpload():
global ID_Photo_filename
ID_Photo_filename=filedialog.askopenfilename()
load=Image.open(ID_Photo_filename)
w, h = load.size
Id_img=ImageTk.PhotoImage(load)
Show_Id=canvas.create_image((w / 2, h / 2), image=Id_img)
root.geometry("%dx%d" % (w/2, h/2))
def PhotoUpload():
global Photo_filename
Photo_filename=filedialog.askopenfilename()
load_photo=Image.open(Photo_filename)
w,h=load_photo.size
Photo_img=ImageTk.PhotoImage(load_photo)
Show_Photo=canvas.create_image((w / 2, h / 2), image=Photo_img)
root.geometry("%dx%d" % (w/2, h/2))
UserName=Label(root,text="UserName")
UserName.pack(side=LEFT)
EnterName=Entry(root)
EnterName.pack(side=LEFT)
canvas.pack(fill=tk.BOTH, expand=True)
Id_Upload = Button(root, text="Upload Id", command=IdUpload)
Photo_Upload = Button(root, text="Upload Photo", command=PhotoUpload)
Compare_photo = Button(root, text="Compare", command=ComparePhoto)
Id_Upload.pack(side=LEFT)
Compare_photo.pack(side=LEFT)
Photo_Upload.pack(side=LEFT)
root.mainloop()
我已经显示了部分代码,我认为如果需要的话,我会发布完整的代码