python - Tkinter Entry 小部件不适用于 .get() 函数
问题描述
我是 python 新手,我正在尝试使用 Tkinter 模块。我想做一个可以注册和登录的应用程序。如果我不将它与 Tkinter 一起使用,则该代码可以工作,但我在 Entry 小部件和 .get() 函数方面遇到了一些问题。
这是我的代码:
import tkinter as tk
def apriR():
global email
global password
hub.withdraw()
log = tk.Tk()
log.geometry("200x200")
log.title("log")
txt1 = tk.Label(log, text = "E-mail")
txt1.grid(row = 0, column = 0)
E1 = tk.Entry(log)
E1.grid(row = 0, column = 1)
txt2 = tk.Label(log, text = "Password")
txt2.grid(row = 1, column = 0)
E2 = tk.Entry(log)
E2.grid(row = 1, column = 1)
email = E1.get()
password = E2.get()
back = lambda : close(log, hub)
Stop = tk.Button(log, text="Go back", command=back)
Stop.grid(row = 3, column = 1)
Invia = tk.Button(log, text="Invia", command=add)
Invia.grid(row = 2, column = 1)
def apriL():
global email
global password
hub.withdraw()
log = tk.Tk()
log.geometry("200x200")
log.title("log")
txt1 = tk.Label(log, text = "E-mail")
txt1.grid(row = 0, column = 0)
E1 = tk.Entry(log)
E1.grid(row = 0, column = 1)
txt2 = tk.Label(log, text = "Password")
txt2.grid(row = 1, column = 0)
E2 = tk.Entry(log)
E2.grid(row = 1, column = 1)
email = E1.get()
password = E2.get()
back = lambda : close(log, hub)
Stop = tk.Button(log, text="go back", command=back)
Stop.grid(row = 3, column = 1)
Invia = tk.Button(log, text="Login", command=log)
Invia.grid(row = 2, column = 1)
def log():
global email
global password
logga = open(f"{email}.txt", "r").read()
if logga == password:
close(log, end)
end = tk.Tk()
end.geometry("200x200")
end.title("Logged")
txt = tk.Label(end, text = "You logged!!!")
back = lambda : close(end, hub)
Stop = tk.Button(end, text="Go Back", command=back)
else:
close(log, end)
end = tk.Tk()
end.geometry("200x200")
end.title("Nope")
txt = tk.Label(end, text = "Incorrect Password")
back = lambda : close(end, hub)
Stop = tk.Button(end, text="Go Back", command=back)
def add():
global email
global password
email = E1.get()
password = E2.get()
registra = open(f"{email}.txt", "w")
registra.write(f"{password}")
registra.close()
def close(log, hub):
log.destroy()
show(hub)
def show(log):
log.update()
log.deiconify()
if __name__ == '__main__':
hub = tk.Tk()
hub.geometry("200x200")
hub.title("hub")
frame = tk.Frame()
frame.pack()
register = tk.Button(frame, text="Register now!", command=apriR)
register.pack()
login = tk.Button(frame, text="Login", command=apriL)
login.pack()
hub.mainloop()
抱歉,如果我插入了所有代码,但我不知道问题出在哪里。(是的,代码可能有很多错误)谢谢!
解决方案
推荐阅读
- tcpdump - tcpdump 中的“oui Unknown”是什么意思?
- c# - transform.SetParent vs TransformPoint(InverseTransformPoint())
- mysql - 插入重复键 - 跳过自动增量 ID
- android - Why id of the views is the same in included layouts?
- vue.js - IE11 中的 Vue.js 错误
- javascript - jQuery幻灯片图像显示不受控制
- github - 我需要输入什么代码才能使 expo 项目功能?
- visual-studio - 如何在 F# 中启用 WinForms 或 WPF 项目?
- sqlite - SQLite.net 数据库与 Xamarin.Forms 应用程序
- scala - 如何在异常时停止 Actor 重新加载