我正在尝试在 TKinter 中编写一个简单的日志记录应用程序。基本上我需要将条目与给定的字符串进行比较(正确的传递)。不幸的是,每当我输入密码时,“entry.get()”方法的结果都会改变输入——打印它返回:
<bound method Entry.get of <tkinter.Entry object .!entry>>
编码
def start_page():
start_window = Tk()
ent_1 = Entry(start_window)
but_1 = Button(start_window, text='Login', command=partial(login, ent_1.get))
but_1.grid(row=1,column=1)
ent_1.grid(row=0, column=1)
start_window.mainloop()
def login(input_password):
correct_password = 'password'
if correct_password == input_password:
coefficient_calc()
start_window.destroy()
else:
print('You typed:', input_password)
print('Please type the correct password.')
知道如何转换它或以所需的形式“获取”条目吗?我发现很少有类似的话题,但没有人回答这个特定的问题。
移动login()
范围内的定义start_window()
解决了问题。无需传递ent_1
(和start_window
)到login()
,也无需使用functools.partial
:
def start_page():
def login():
input_password = ent_1.get()
correct_password = 'password'
if correct_password == input_password:
coefficient_calc()
start_window.destroy()
else:
print('You typed:', input_password)
print('Please type the correct password.')
start_window = Tk()
ent_1 = Entry(start_window)
but_1 = Button(start_window, text='Login', command=login)
but_1.grid(row=1,column=1)
ent_1.grid(row=0, column=1)
start_window.mainloop()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句