【发布时间】:2019-03-20 17:38:33
【问题描述】:
我正在尝试使用 Tkinter gui 将图像放在按钮上,但按钮不是照片,而是白色方块。 我使用这些行:
button = tk.Button(self.root, height=100, width=165,
text=name_to_teach_command, command=action_with_args)
st = ImageTk.PhotoImage(file=photo_location)
button.config(image=st)
button.configure(relief=FLAT)
感谢您的帮助!
【问题讨论】:
-
这是因为局部变量
st用于保存一旦函数退出将被销毁的图像。这种问题已经回答了几十次了。 -
@acw1668 已经在stackoverflow.com/questions/54815388/…回复了一个几乎完全相同的副本