I'm new to python and got stuck while trying to build a GUI. I can't find a way to extract data from the 'login' function, which would be the new TopLevel window created after the user logs in. Because of that, I have to write the remaining code inside the 'login function', but I have the impression that there must be another way around. I tried making the new top level global, but it returns that the new variable is not defined.
from tkinter import *  
from tkinter import messagebox
root = Tk()
login_frame = LabelFrame(root, text = "login info").pack()
user_field = Label(login_frame, text = "user: ")
user_field.grid(row = 0,column = 0)
pass_field = Label(login_frame, text = "pass: ")
pass_field.grid(row = 1, column = 0)
user_input = Entry(login_frame)
user_input.grid(row = 0, column = 1)
pass_input = Entry(login_frame, show = "*")
pass_input.grid(row = 1, column = 1)
def login():
if user_input.get() == "user" and pass_input.get() == "user":
    if messagebox.showinfo("blah", "blah") == "ok":
        pass_input.delete(0, END)
        user_input.delete(0, END)
        root.withdraw()
        **app = Toplevel()**
else:
    messagebox.showerror("blah", "blah")
    pass_input.delete(0, END)
    user_input.delete(0, END)
login_btn = Button(login_frame, text = "LOGIN")
login_btn.grid(row = 2, column = 0)
exit_btn = Button(login_frame, text = "SAIR")
exit_btn.grid(row = 2, column = 1)    
root.mainloop()