from tkinter import *
def login():
root = Tk()
root.resizable(False, False)
root.title("Log in")
root.geometry("300x200")
root.configure(bg='#AFFDFF')
def submit(usernameEntry):
with open("username.txt", "w") as myFile:
myFile.write(usernameEntry.get())
Label(root, text="Please enter your username", bg='#AFFDFF').place(relx=0.5, rely=0.35,
anchor=CENTER)
usernameEntry = Entry(root, width=25).place(relx=0.5, rely=0.5, anchor=CENTER)
submitBtn = Button(root, text="Submit", bg='#A4FFCB', command=lambda:
submit(usernameEntry)).place(relx=0.5, rely=0.65, anchor=CENTER)
root.mainloop()
My output is:
Traceback (most recent call last):
File "C:\Users\george\anaconda3\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "c:\Users\george\Desktop\rock paper scissors\interface.py", line 48, in <lambda>
submitBtn = Button(root, text="Submit", bg='#A4FFCB', command=lambda:
submit(usernameEntry)).place(relx=0.5, rely=0.65, anchor=CENTER)
File "c:\Users\george\Desktop\rock paper scissors\interface.py", line 44, in submit
myFile.write(usernameEntry.get())
AttributeError: 'NoneType' object has no attribute 'get'
Please help me with this. I'm stuck for a while now. I have also tried not referancing 'usernameEntry' to submit function and it didn't work.