我将如何修复错误"AttributeError: 'Window' object has no attribute 'submit_button'"



我在检查按钮文本时不断收到错误。错误是";AttributeError:"Window"对象没有属性"submit_button"。我试图在其他地方添加它,但仍然代码:

def creation(self):
if self.submit_button['text'] != "Create a file":
time.sleep(3)
self.submit_button['text'] = "Create a file"
self.submit_button['foreground'] = "black"
self.creation_title = tk.Label(text="File creator:", font=("arial", 25))
self.name_label = tk.Label(text="Name:")
self.age_label = tk.Label(text="Age:")
self.height_label = tk.Label(text="Height:")
self.citizen_status_label = tk.Label(text="Citizenship Status:")
self.submit_button = tk.Button(text="Create a file", command=self.creator, height=3, width=20)
self.back_button = tk.Button(text="close", command=lambda: [self.options(), self.destroyer("creation")],
height=1, width=5)
self.name_entry = tk.Entry(self.root)
self.age_entry = tk.Entry(self.root)
self.height_entry = tk.Entry(self.root)
self.citizen_status = tk.StringVar()
self.citizen_status_valid = tk.Radiobutton(text="Valid", variable=self.citizen_status, value="VALID")
self.citizen_status_invalid = tk.Radiobutton(text="Invalid", variable=self.citizen_status, value="INVALID")
self.creation_title.place(x=20, y=25)
self.name_label.place(x=250, y=97.5)
self.age_label.place(x=262, y=137.5)
self.height_label.place(x=248, y=177.5)
self.citizen_status_label.place(x=191, y=217.5)
self.submit_button.place(x=20, y=150)
self.back_button.place(x=20, y=250)
self.name_entry.place(x=300, y=100)
self.age_entry.place(x=300, y=140)
self.height_entry.place(x=300, y=180)
self.citizen_status_valid.place(x=295, y=220)
self.citizen_status_invalid.place(x=362.5, y=220)
print("Creation Menu Created")```

在使用属性之前需要定义它。函数中的第一行代码使用self.submit_button,但直到几行之后才定义self.submit_button

相关内容

最新更新