Tkinter - Open one window and close another

前端 未结 2 625
闹比i
闹比i 2021-01-16 18:30

I want to have a login screen and when the login is successful, the screen is closed and a new screen is created. The problem is , when I do just like the following code , b

2条回答
  •  攒了一身酷
    2021-01-16 19:13

    Slayer , I did like you said and it worked like a charm! Here is the example code:

    from tkinter import *
    
    class Tela_login(Frame):
        def __init__(self,master):
            Frame.__init__(self, master)
            self.grid()
            self.button1 = Button(text = "Open",command = lambda: self.open_login())
            self.button1.grid()
    
        def open_login(self):
            root2 = Toplevel()
            app2 = Tela_principal(root2)
    
    class Tela_principal(Frame):
        def __init__(self,master):
            Frame.__init__(self, master)
            self.grid
    
    root = Tk()
    root.geometry("800x600")
    app = Tela_login(root)
    root.mainloop()
    

提交回复
热议问题