【发布时间】:2014-07-14 09:30:37
【问题描述】:
我正在尝试制作一个自定义弹出窗口作为我正在制作的程序的关于屏幕,但是当我尝试在调用弹出窗口之前存在另一个窗口时,我收到一条 tcl 消息,说图像不存在.作为记录,我正在使用 python 3.3.4
我的代码的完整摘录是:
#!python3
from tkinter import *
import PIL.ImageTk
import os
__version__ = "part number"
class Screen():
def __init__(self):
aboutscreen = Tk()
aboutscreen.title("About")
aboutscreen.photoimg = PIL.ImageTk.PhotoImage(file="Logo.bmp")
Label(aboutscreen, image=aboutscreen.photoimg).pack()
Label(aboutscreen, text = "company name", width = 25, font = ("ariel",16)).pack()
Label(aboutscreen, text = "program name", width = 30, font = ("ariel",12)).pack()
Label(aboutscreen, text = "Part Number: " + __version__, width = 30, font = ("ariel",12)).pack()
Label(aboutscreen, text = "Copyright company name", width = 30, font = ("ariel",12)).pack()
while 1:
try: aboutscreen.update() #keep update window updated until destroyed
except: break #break loop when destroyed
if __name__ == "__main__":
root = Tk()
app = Screen()
这段代码给了我错误信息:
line 15, in __init__
Label(aboutscreen, image=aboutscreen.photoimg).pack()
File "C:\Python33\lib\tkinter\__init__.py", line 2607, in __init__
Widget.__init__(self, master, 'label', cnf, kw)
File "C:\Python33\lib\tkinter\__init__.py", line 2086, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: image "pyimage1" doesn't exist
但如果我注释掉 root = Tk() 行,它就可以工作。
谁能解释我哪里出错了?
谢谢
詹姆斯
【问题讨论】:
标签: python tkinter python-3.3