【发布时间】:2015-01-18 11:10:34
【问题描述】:
看到这里,PhotoImage not showing up the image associated with it我想知道为什么省略选项类型不会引发错误,而不是不显示图像?
此代码不显示图像而不会引发任何错误
import tkinter as tk
root = tk.Tk()
image1 = tk.PhotoImage("ban.gif")
tk.Label(root,image=image1).pack()
tk.Label(root, text="some string here").pack()
root.mainloop()
但是这个很好用
import tkinter as tk
root = tk.Tk()
image1 = tk.PhotoImage(file="ban.gif")
tk.Label(root,image=image1).pack()
tk.Label(root, text="some string here").pack()
root.mainloop()
在 effbot 上它没有说明任何内容,所以我检查了 tcl 手册页中的 creating photos,但仍然找不到它为什么会这样。
另外,如果这两个是重复的,请告诉我,以便我删除/关闭投票。
【问题讨论】:
-
“创建照片”的链接与您的问题无关——该链接指向如何将图像添加到画布。