Python 在Tkinter有类似的问题

Python 在Tkinter有类似的问题,python,tkinter,attributes,Python,Tkinter,Attributes,这是我的代码,我经常遇到属性错误,我不知道错误在哪里: from tkinter import* class Student: def __init__(self,root): self.root=root self.root.title("Customer Management System") self.root.geometry("1350x780+0+0") title=L

这是我的代码,我经常遇到属性错误,我不知道错误在哪里:

from tkinter import*
class Student:
    def __init__(self,root):
    
       self.root=root
       self.root.title("Customer Management System")
       self.root.geometry("1350x780+0+0")

       title=Label(self,root,text="SUNBIRD TAILORS",font=("times new 
       roman",40,"bold"),bg="blue",fg="white")
       title.pack(side=TOP)
   
 root=Tk()
 ob = Student(root)
 root.mainloop()
错误如下所示: self.tk=master.tk
属性错误:“学生”对象没有属性“tk”

您正在使用
self
作为
Label
的第一个参数。该参数必须是小部件,但
Student
不是小部件。只需删除
self

title=Label(root,text="SUNBIRD TAILORS",font=("times new roman",40,"bold"),bg="blue",fg="white")

请在
标签
参数中发布完整的回溯摆脱
self
。它可能不会解决您当前的问题,但会解决您将遇到的下一个问题。。。实际上,它可能会解决您当前的问题
self
Student
Student
不是
widget
,但您正试图将其用作主控程序。实际上,您尝试将这些内容连接在一起的方式很糟糕。键入错误,
Label(self,root,…)
应该是
Label(self.root,…)