我收到此消息:图像“pyimage2”不存在。我想要多个带有图像的窗口,如何实现?
这是我的代码:
import Image
import ImageTk
import Tkinter
def new():
wind = Tkinter.Tk()
wind.geometry('600x600') # This not work, why?
imageFile2 = Image.open("someimage2.jpg")
image2 = ImageTk.PhotoImage(imageFile2)
panel2 = Tkinter.Label(wind , image=image2)
panel2.place(relx=0.0, rely=0.0)
wind.mainloop()
master = Tkinter.Tk()
master.geometry('600x600') # This work fine
imageFile = Image.open("someimage.jpg")
image1 = ImageTk.PhotoImage(imageFile)
panel1 = Tkinter.Label(master , image=image1)
panel1.place(relx=0.0, rely=0.0)
B = Tkinter.Button(master, text = 'New image', command = new).pack()
master.mainloop()
最佳答案
将 wind = Tkinter.Tk()
更改为 wind = Tkinter.Toplevel()
:
def new():
wind = Tkinter.Toplevel()
wind.geometry('600x600')
这就是您需要更改的全部内容。
<小时/>引用:
关于python - PIL 和 Tkinter,多窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8111739/