-1

I tried creating a login system. it gives me a: 'NoneType' object has no attribute 'get'

here is the code:

import tkinter
from tkinter import ttk

window = tkinter.Tk()

def addUsernm():
    a = usernl.get("1.0", 'end-1c')
    print(a)

usernames = []
passwords = []

usernl = tkinter.Entry(window).pack()
passwrdnl = tkinter.Entry(window).pack()



submitbtn = tkinter.Button(window,text="submit",command=addUsernm).pack()

window.mainloop()

How do I fix this?

1 Answers1

2

The issue is, you're confusing the Text widget get method, with the Entry widget get method, and they aren't the same method. Also you can't use pack on the same line as widget or the variable won't be saving anything. This is the solution that worked for me:

from tkinter import Tk, Entry, Button

window = Tk()
window.state("zoomed")

def add():
    a = user.get()
    b = password.get()
    print(a, b)


user = Entry(window)
user.pack()
password = Entry(window)
password.pack()

Button(window, text="submit", command=add).pack()

window.mainloop()
Matiiss
  • 5,970
  • 2
  • 12
  • 29
Sten Healey
  • 106
  • 6