由于某种原因,我不能再使用.get()
函数了
这是我的密码:
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()
过去它很管用,所以我真的不知道该怎么办
我得到的错误如下所示:
un = str(username.get()) AttributeError: 'NoneType' object has no attribute 'get'
代码中的变量username、password和btn并不像您想象的那样是
Entry()
、Entry()
和Button()
对象,而是pack()
方法的返回(似乎它不返回任何东西,所以所有这些都是非类型对象)如果您打算在代码中以
Entry()
或Button()
对象的形式访问这些对象,则应将initiation和pack()
分为两行,如下所示:相关问题 更多 >
编程相关推荐