Search code examples
pythontkinterexitdestroymainloop

how can i run a code after the function root.destroy


hello i'm working on python using tkinter , i want to run a window (in Main) after destroy the first window in Login class , but the problem is that the code stop at the root.destroy and don't execute the reste of the code

i tried to replace root.destroy() by root.qui() , the rest of the code continue to execute but the first window still appear

from tkinter import *
import threading

class Login:
    def __init__(self):
        self.window=Tk()
        self.window.geometry("600x500+50+50")
        self.window.resizable(False,False)
        self.window.configure(bg="#fafafa")

    def start(self):
        self.window.mainloop()

    def stop(self):
        self.window.destroy()


class Main: 
    def __init__(self):
        self.login=Login()


   def test(self):
        a=input("a : ")
        b=input("b : ")

        if a ==b:
            self.login.stop()
        print("window destroyed .....")

test=Main()
threading.Thread(target=test.test).start()
test.login.start()

Solution

  • finally i found a solution for the problem, in the method login.stop()

    i replaced the instruction window.destroy() by window.after(0,window.destroy)