Hello,
I have a test code snippet of which I read in the user name and password. However, when
I attempt to read the entered input via the ‘get()’ function/method, I keep getting the following error:
AttributeError: 'NoneType' object has no attribute 'get'
My code snippet is:
import tkinter as tk
class login(tk.Tk):
def __init__(self):
super().__init__()
tk.Tk.title(self,'PN: F4581-01 Test') # Window title (not real pn)
tk.Tk.geometry(self, '280x150')
login_info = tk.LabelFrame(self, padx = 15, pady = 10,
text = "Login Info")
tk.Label(login_info, text = "First name").grid(row = 0)
tk.Label(login_info, text = "Password").grid(row = 1)
self.name = tk.Entry(login_info).grid(row = 0, column = 1, sticky = tk.W)
self.password = tk.Entry(login_info, show = '*').grid(row = 1, column = 1, sticky = tk.W)
login_info.pack(padx = 10, pady = 10)
self.btn_start_test = tk.Button(self, text = "Start Test", command = self.print_password)
self.btn_start_test.pack(padx = 10, pady = 10, side = tk.BOTTOM)
def print_password(self): # test method to verify password entry
print('Hello everyone!')
print('Password: {}'.format(self.name.get()))
print('Password: {}'.format(self.password.get()))
if __name__ == "__main__":
app = login()
app.mainloop()
Can someone please help as to why the get() method is not working as expected.