Reputation: 21
On click of the button clk the first instance of the window opens but after destroying the first window, the successive windows does not open. Only after the main instance win is closed the successive windows open.
from tkinter import *
def func():
root = Tk()
b1 = Button(root,text='Click Me!').pack()
root.after(2000, lambda: root.destroy())
root.mainloop()
root=Tk()
b1 = Button(root,text='Click Me!',bg='orange').pack()
root.mainloop()
win = Tk()
clk = Button(win,text='func',command=func).pack()
win.mainloop()
There is no syntax error, but I'm not getting the output that I want.
Thank You
Upvotes: 0
Views: 202
Reputation: 631
At best of my understanding there can be only one mainloop(). I rewrote your code to make it work.
from tkinter import *
def func():
root = Toplevel()
b1 = Button(root,text='Click Me!').pack()
root.after(2000, lambda: second(root))
def second(root):
root.destroy()
root=Toplevel()
b1 = Button(root,text='Click Me!',bg='orange').pack()
win = Tk()
clk = Button(win,text='func',command=func).pack()
win.mainloop()
Upvotes: 1