Python 我试图在tk窗口中的函数错误中添加图像:-image";pyimage4“;不';不存在
这是我的密码:Python 我试图在tk窗口中的函数错误中添加图像:-image";pyimage4“;不';不存在,python,python-3.x,tkinter,Python,Python 3.x,Tkinter,这是我的密码: global ad4 global background global background_l def getvals(): print(f"the value of username is {uservalue.get()}") print(f"the value of password is {passvalue.get()}") if (uservalue.get()).casefold()==&quo
global ad4
global background
global background_l
def getvals():
print(f"the value of username is {uservalue.get()}")
print(f"the value of password is {passvalue.get()}")
if (uservalue.get()).casefold()=="avvh".casefold() and passvalue.get()=="vhjbjh":
b=Tk()
b.geometry("600x400")
ad4 = Image.open("My Post.jpg")
ad4 = ad4.resize((600, 400), Image.ANTIALIAS)
background = ImageTk.PhotoImage(ad4)
background_l = Label(b,image=background).pack()
background_l.place(x=0, y=0, relwidth=1, relheight=1)
b.mainloop()
try:
label(a).destroy()
except:
pass
else:
c=Label(a,text="incorrect pass or user name",fg="red").grid()
错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\python 3.8.1\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "C:/Users/pc/PycharmProjects/firstfrog/PyGame/new.py", line 274, in getvals
background_l = Label(b,image=background).pack()
File "C:\python 3.8.1\lib\tkinter\__init__.py", line 3143, in __init__
Widget.__init__(self, master, 'label', cnf, kw)
File "C:\python 3.8.1\lib\tkinter\__init__.py", line 2567, in __init__
self.tk.call(
_tkinter.TclError: image "pyimage4" doesn't exist
此错误通常在多次创建
Tk()
时发生,对于辅助窗口,请将Tk()
替换为Toplevel()
这是否回答了您的问题?谢谢,这对我有用。