【发布时间】:2022-01-03 06:16:40
【问题描述】:
我想在我的骰子函数中放一张图片,如果有人能告诉我我需要添加什么以便我可以将图片作为页面背景,我将不胜感激
def dice():
tk = Tk()
tk.geometry('300x300')
img = PhotoImage(file='dicee.gif')
lb5 = Label(tk,image=img)
lb5.pack()
btn4=Button(tk,text="Roll The Dice",command=dice)
btn4.place(x=110,y=130)
tk.mainloop()
它显示给我的错误是:
self.tk.call(
_tkinter.TclError: image "pyimage1" doesn't exist
【问题讨论】:
-
问题的根源在于您创建了多个
Tk的实例。对于第二个窗口,您需要使用Toplevel。
标签: python image tkinter button