Tkinter loading images in the frame
我使用的是python 2.7,我想在tkinter框架上加载一个.gif徽标,但它始终打开两个窗口(一个空窗口,一个带徽标)。Codes:
1 2 3 4 5 6 | import Tkinter root = Toplevel() logo = PhotoImage(file="D:\\.....\\....\\****.gif") w1 = Label(root, compound = CENTER, image = logo).pack(side="right") root.mainloop() |
我怎么能只有一个带标志的窗口?
每个tkinter应用程序都需要一个
1 | root = Toplevel() |
到
1 | root = Tk() |
号
另外,请保留您的
When you add a PhotoImage or other Image object to a Tkinter widget,
you must keep your own reference to the image object. If you don’t,
the image won’t always show up.The problem is that the Tkinter/Tk interface doesn’t handle references
to Image objects properly; the Tk widget will hold a reference to the
internal object, but Tkinter does not. When Python’s garbage collector
discards the Tkinter object, Tkinter tells Tk to release the image.
But since the image is in use by a widget, Tk doesn’t destroy it. Not
completely. It just blanks the image, making it completely
transparent…
号