I can't use the .get()
function anymore for some reason.
Here is my code:
import tkinter
from tkinter import *
def submit():
file = open('database.txt', 'w')
file.write('Username:', un, '\nPassword:', pw)
file.close()
wn = Tk()
wn.geometry('500x200')
Label(text='Geben Sie hier Ihren Benutzername ein:').pack()
username = Entry().pack()
Label(text='\n').pack()
Label(text='Geben Sie hier Ihr Passwort ein:').pack()
password = Entry().pack()
Label(text='\n').pack()
un = str(username.get())
pw = str(password.get())
btn = Button(text='Submit', command=submit).pack()
wn.mainloop()
It used to work in the past, so I don't really know what to do.
The error I get looks like this:
un = str(username.get()) AttributeError: 'NoneType' object has no attribute 'get'
Variables username, password and btn in your code are not Entry()
, Entry()
and Button()
objects as you might think, but the returns of pack()
method (it seems it doesn't return anything, so all of these are NoneType objects).
If you intend to access these objects as Entry()
or Button()
objects further down in your code, you should separate initiation and pack()
into two lines as:
username = Entry()
username.pack()
password = Entry()
password.pack()
btn = Button(text='Submit', command=submit)
btn.pack()