0

I have something like this:

first.py

from tkinter import *

def new_window(event):
    root.destroy()
    import second

root = Tk()
b = Button(root, text='New window')
b.pack()
b.bind('<Button-1>', new_window)
root.mainloop()

second.py

from tkinter import *
root = Tk()
root.mainloop()

But when I open the second window, the first one is destroyed (I hope so), but the second one is frozen (it is shown, but there is no close-button on the top and I only see the launch-icon). Why is it so? Don't I kill the first loop?

Nae
  • 14,209
  • 7
  • 52
  • 79
  • describe it better – AD WAN Feb 07 '18 at 16:07
  • Welcome to [so]! +1 For asking a good question with a well written [mcve]! Easiest workaround would probably using OOP, as in instead of having your main script jump on other scripts, create classes in other scripts to have GUI-like objects and simply create & destroy them in your main-script. See [this answer](https://stackoverflow.com/a/17470842/7032856) as a starting point perhaps, it really helped me very much. – Nae Feb 08 '18 at 13:12

1 Answers1

2

The problem is likely because import second never returns since the last thing it does is call root.mainloop(). Since it never returns, the callback in the first window never finishes. And since it never finishes, it's not able to process any other events.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685