python - PIL 和 Tkinter,多窗口

标签 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()

最佳答案

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

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

这就是您需要更改的全部内容。

<小时/>

引用:

关于python - PIL 和 Tkinter,多窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8111739/

相关文章:

python - django模型字段中字符串参数的含义是什么?

python - 无法将数据推送到 Azure 事件中心

python - 从 kwargs 中删除一个参数。那可能吗?

python - Python中尖括号的含义是什么?

Python-为什么不同的Tk标签显示为相同的坐标和不同的对象?

python - 如何通过按下按钮关闭 Tkinter 窗口?

python - 使用 Tkinter 的提醒

python - 在 Kivy Canvas 上显示 PIL 图片

android - 使用带有枕头的 buildozer 构建 apk : _imaging issue

django admin 上传图片到s3然后调整图片大小和保存thumb问题