Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我试图在tk窗口中的函数错误中添加图像:-image";pyimage4“;不';不存在_Python_Python 3.x_Tkinter - Fatal编程技术网

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()
这是否回答了您的问题?谢谢,这对我有用。