Tkinter Entry小部件不能与.get()函数一起使用

时间:2019-07-27 12:00:12

标签: python tkinter tkinter-entry

我是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()

对不起,如果我插入所有代码,但不知道问题出在哪里。 (是的,代码中可能有很多错误) 谢谢!

0 个答案:

没有答案