如何在Python中的Tkinter窗口上设置背景图片?
这是设置背景的代码:如何在Python中的Tkinter窗口上设置背景图片?,python,tkinter,Python,Tkinter,这是设置背景的代码: ''' Background picture: ''' background_image=tk.PhotoImage("blood_PNG6140.png") background_label = tk.Label(parent, image=background_image) background_label.place(x=0, y=0, relwidth=1, relheight=1) 我得到这个错误: Traceback (most recent call la
'''
Background picture:
'''
background_image=tk.PhotoImage("blood_PNG6140.png")
background_label = tk.Label(parent, image=background_image)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
我得到这个错误:
Traceback (most recent call last):
File "/Users/Lana/Desktop/Zaid/End_Projekt_MakE_YouR_ChoicE_zaid_zaim ON MAC/MakeYourChoice.py", line 275, in <module>
background_image=tk.PhotoImage("blood_PNG6140.png")
NameError: name 'tk' is not defined
>>>
回溯(最近一次呼叫最后一次):
文件“/Users/Lana/Desktop/Zaid/End_Projekt_MakE_YouR ChoicE_Zaid_zaim ON MAC/MakeYourChoice.py”,第275行,在
背景图片=tk.PhotoImage(“blood\u PNG6140.png”)
NameError:未定义名称“tk”
>>>
提前谢谢你!
ZZaim您忘记导入
tkinter
。放置
import tkinter as tk
在.py文件的标题中。将
导入tkinter作为tk
添加到代码顶部您需要将tkinter作为tk导入。另一个错误是:第277行,在background\u label=tk.label(parent,image=background\u image)name错误:未定义名称“parent”>>第276行,在parent=tkinter.tk()中AttributeError:“模块”对象没有属性“tk”