在Tkinter有类似的问题

2024-05-07 02:13:15 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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”


1条回答
网友
1楼 · 发布于 2024-05-07 02:13:15

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

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

相关问题 更多 >