Python (“AttributeError:';PhotoImage';对象没有属性';#PhotoImage(照片';)[Tkinter]

Python (“AttributeError:';PhotoImage';对象没有属性';#PhotoImage(照片';)[Tkinter],python,tkinter,Python,Tkinter,代码: 上面是一段代码,用于在python中创建注册表单并获得以下错误。在python中使用tkinter模块,我正在创建注册表单,这意味着当我在窗口中设置背景图像时,self.bg=ImageTk.PhotoImage(file=“Images/failter.jpg”)和error raise,我从联机获取图像并将其设置为高度和宽度 错误: from tkinter import* from PIL import Image,ImageTk class Register: def

代码:

上面是一段代码,用于在python中创建注册表单并获得以下错误。在python中使用tkinter模块,我正在创建注册表单,这意味着当我在窗口中设置背景图像时,
self.bg=ImageTk.PhotoImage(file=“Images/failter.jpg”)
和error raise,我从联机获取图像并将其设置为高度和宽度

错误:

from tkinter import*
from PIL import Image,ImageTk

class Register:
    def __init__(self,root):
        self.root = root
        self.root.title("Registration Window")
        self.root.geometry("1350x700+0+0")

        self.bg = ImageTk.PhotoImage(file="Images/waterfall.jpg")
        bg = Label(self.root,image = self.bg).place(x=250,y=0,relwidth=1,relheight=1)

root = Tk()*emphasized text*
obj = Register(root)
root.mainloop()
回溯(最近一次呼叫最后一次):
文件“d:\Login with Database\register.py”,第16行,在
obj=寄存器(根)
文件“d:\Login with Database\register.py”,第10行,在\uuuu init中__
self.bg=ImageTk.PhotoImage(file=“Images/falter.jpg”)
文件“C:\Python\Python38\lib\site packages\PIL\ImageTk.py”,第89行,在\uuu init中__
图像=\u从\u获取\u图像\u功率(kw)
文件“C:\Python\Python38\lib\site packages\PIL\ImageTk.py”,第58行,在\u get\u image\u from\u kw中
返回Image.open(源代码)
打开文件“C:\Python\Python38\lib\site packages\PIL\Image.py”,第2878行
fp=内置的.open(文件名为“rb”)
FileNotFoundError:[Errno 2]没有这样的文件或目录:“Images/failter.jpg”
在中忽略异常:
回溯(最近一次呼叫最后一次):
文件“C:\Python\Python38\lib\site packages\PIL\ImageTk.py”,第118行,在__
name=self.\u photo.name
AttributeError:“PhotoImage”对象没有属性“\u PhotoImage\u photo”

这里是重要的部分:
FileNotFoundError:[Errno 2]没有这样的文件或目录:“Images/failter.jpg”
。最有可能的情况是,该文件不存在,或者您没有在您认为存在的目录中运行。我创建了一个名为login database的文件夹,该文件夹包含一个包含2个图像的图像文件夹和一个名为register.py的文件。要运行此程序,所有资源都位于1个文件夹中。。所以…错误已经解决了,谢谢你的帮助@用户2357112支持Monica
Traceback (most recent call last):
  File "d:\Login with Database\register.py", line 16, in <module>
    obj = Register(root)
  File "d:\Login with Database\register.py", line 10, in __init__
    self.bg = ImageTk.PhotoImage(file="Images/waterfall.jpg")
  File "C:\Python\Python38\lib\site-packages\PIL\ImageTk.py", line 89, in __init__
    image = _get_image_from_kw(kw)
  File "C:\Python\Python38\lib\site-packages\PIL\ImageTk.py", line 58, in _get_image_from_kw
    return Image.open(source)
  File "C:\Python\Python38\lib\site-packages\PIL\Image.py", line 2878, in open
    fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'Images/waterfall.jpg'
Exception ignored in: <function PhotoImage.__del__ at 0x000001928E23C430>
Traceback (most recent call last):
  File "C:\Python\Python38\lib\site-packages\PIL\ImageTk.py", line 118, in __del__
    name = self.__photo.name
AttributeError: 'PhotoImage' object has no attribute '_PhotoImage__photo'