-1

I just started learning python and wanted to make a simple login GUI. I tried following a tutorial, but for some reason, my code always gets an error. Here's the error: line 18, in sign_in print(f"My username is {username.get()} and my password is {password.get()}") AttributeError: 'NoneType' object has no attribute 'get'

from tkinter import *

main_window = Tk()



# ---------- LABELS ----------
Label(main_window, text = "Username: ").grid(row = 0, column = 0)
Label(main_window, text = "Password: ").grid(row = 1, column = 0)

# ---------- TEXT INPUT ----------
username = Entry(main_window, width = 50, borderwidth = 3.5).grid(row = 0, column = 1)
password = Entry(main_window, width = 50, borderwidth = 3.5, show = "*").grid(row = 1, column = 1)

# ---------- METHODS ----------
def sign_in():
    print(f"My username is {username.get()} and my password is {password.get()}")

# ---------- BUTTON ----------
Button(main_window, text = "Sign In", command = sign_in).grid(row = 2, column = 1)

# ---------- MAIN LOOP ----------
main_window.mainloop()
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
MarKK
  • 13
  • 2

1 Answers1

0

The problem is when you are defining username and password, you are griding it aswell. Instead, you should grid the username and password Entry's seperately, like this:

    from tkinter import *

    main_window = Tk()
    
    
    
    # ---------- LABELS ----------
    Label(main_window, text = "Username: ").grid(row = 0, column = 0)
    Label(main_window, text = "Password: ").grid(row = 1, column = 0)
    
    # ---------- TEXT INPUT ----------
    username = Entry(main_window, width = 50, borderwidth = 3.5) # Remove grid here
    password = Entry(main_window, width = 50, borderwidth = 3.5, show = "*")

    username.grid(row=0, column=1) # grid Entry's seperately
    password.grid(row=1, column=1)
    
    # ---------- METHODS ----------
    def sign_in():
        print(f"My username is {username.get()} and my password is {password.get()}")
    
    # ---------- BUTTON ----------
    Button(main_window, text = "Sign In", command = sign_in).grid(row = 2, column = 1)
    
    # ---------- MAIN LOOP ----------
    main_window.mainloop()
AashirOverflow
  • 103
  • 1
  • 8