我將顯示減少的部分代碼,這給我一個問題。爲什麼python photoimages不存在?
「_tkinter.TclError:圖像‘pyimageN’不存在」 - 其中N停留1或2或3等等
有示出使用在圖像的菜單的第一類背景。
class MenuWindow(): #in this class we show the main part of the program
def __init__(self):
self.Menu=Tk()
self.MCanvas=Canvas(self.Menu)
self.MCanvas.bind("<ButtonPress-1>",self.MenuClick)
#unuseful lines that configure the window and the canvas#
self.Background=PhotoImage(height=600,width=700)#a simple tkinter.PhotoImage object
#other unuseful lines that draw the photoimage (without reading any file, with the method put())#
self.MCanvas.create_image((x,y),image=self.Background,state="normal")
#unuseful lines that continue the drawing of the canvas#
而第二個類顯示另一個窗口,在後臺使用另一個圖像。這個類由第一個類通過self.MenuClick函數的點擊綁定啓動。
class EditorWindow(): #in this class we show the main part of the program
def __init__(self):
self.Eenu=Tk()
self.ECanvas=Canvas(self.Eenu)
#unuseful lines that configure the window and the canvas#
self.Background=PhotoImage(height=600,width=700)
#other unuseful lines that draw the photoimage (without reading any file , with the method put())#
self.ECanvas.create_image((x,y),image=self.Background,state="normal")#in this line i get the error
#unuseful lines that continue the drawing of the canvas#
的complere回溯如下:
Exception in Tkinter callback
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/tkinter/__init__.py", line 1399, in __call__
return self.func(*args)
File "/Users/albertoperrella/Desktop/slay.py", line 70, in MenuClick
EditorWindow(self)
File "/Users/albertoperrella/Desktop/slay.py", line 85, in __init__
self.ECanvas.create_image((3,3),image=self.Background,state="normal",anchor="nw")
File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/tkinter/__init__.py", line 2140, in create_image
return self._create('image', args, kw)
File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/tkinter/__init__.py", line 2131, in _create
*(args + self._options(cnf, kw))))
_tkinter.TclError: image "pyimage2" doesn't exist
這兩個類都以類似的方式進行,所以我不知道爲什麼我的錯誤與第二個。我相信,這不是一個寫錯誤,例如(重構而不是構造),並且我正在使用的圖像實際上存在。
所以我認爲:
我提出一些概念錯誤,
,或者是(或微妙的行爲的Tkinter的)在python
哪一行引發錯誤?你可以發佈回溯? – mgilson
我覺得需要更多'PhotoImage()'的細節,因爲這似乎是圖像的來源。 – unwind