Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

function' object has no attribute 'destroy'

It says function’ object has no attribute ‘destroy
When I press the register button, the register wwindow could not be destory and goes to the next page.

Designing for registration

def register():
global register_screen
register_screen = Toplevel(root)
register_screen.title("Register")
register_screen.geometry("300x250")

global username
global password
global username_entry
global password_entry
username = StringVar()
password = StringVar()

Label(register_screen, text="Please enter details below").pack()
Label(register_screen, text="").pack()
username_lable = Label(register_screen, text="Username")
username_lable.pack()
username_entry = customtkinter.CTkEntry(master=register_screen,textvariable=username, placeholder_text="Username")
username_entry.pack(padx=20, pady=10)
password_lable = Label(register_screen, text="Password")
password_lable.pack()
password_entry = customtkinter.CTkEntry(master=register_screen,textvariable=password, placeholder_text="Password")
password_entry.pack(padx=20, pady=10)
Label(register_screen, text="").pack()
register_button_1= customtkinter.CTkButton(master=register_screen, text="Register", command = onClick,height = 35, width = 250 )
register_button_1.place(relx=0.5, rely=0.8, anchor=tkinter.CENTER)

#When the register button is click the emial and the passwrod will be sotre in a text file 
def onClick():
f = open('hi.txt','a')
f.write(username.get()+' '+password.get()+'\n')
f.close()
register.destroy()
login()

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

register is a function you defined at the top of the snippet, and as the error says, it has no attribute called destroy. It seems like you meant to call register_screen.destroy().

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading