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

usernam.get() and password.get() in def login() …dont work

I don’t know why it dont work even when I copy somone code it work but when I do my code it dont work .

I want to get the username and the password so I can verify the login else it will show a message box.


from tkinter import *
    
def login():

    usrnam = username.get()
    paswrd = password.get()

    print(username)


root = Tk()
photo = PhotoImage(file='small logo.png')
root.geometry('300x500+450+100')
root.title('Clinique nouadhibou')
root.config(background='white')
root.iconphoto(True,photo)


label1 = Label(root, text="bonjour !", font=('Arial', 20, 'bold'), bg='white', fg='green', relief=RAISED, bd=10, image=photo, compound='top').pack()

username = Entry(root).place(x=95, y=320)

password = Entry(root, show='*').place(x=95, y=340)


who_is_this = Checkbutton(root).place(x=0, y=480)
button = Button(root, text='Enter !', command=login).place(x=137, y=360)
button = Button(root, text='SORTIR!', command=quit).place(x=130, y=470)

root.mainloop()

It give me this error:

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

File "clinique.py", line 14, in login
   usrnam = username.get()
AttributeError: 'NoneType' object has no attribute 'get'

>Solution :

.place() returns None. You should declare the widget on one line, and place it on the next one, then reference the declaration.

Example:

# old code
username = Entry(root).place(x=95, y=320)

password = Entry(root, show='*').place(x=95, y=340)

# new code
username = Entry(root)
username.place(x=95, y=320)

password = Entry(root, show='*')
password.place(x=95, y=340)
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