PIL和Tkinter,多窗口

时间:2011-11-13 13:08:47

标签: python tkinter python-imaging-library

我有这样的信息:图片“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()

1 个答案:

答案 0 :(得分:3)

wind = Tkinter.Tk()更改为wind = Tkinter.Toplevel()

def new():
    wind = Tkinter.Toplevel()
    wind.geometry('600x600')       

这就是你需要改变的全部。


参考: