Reputation: 647
from tkinter import *
root = Tk()
root.geometry("500x500")
toplevel = Toplevel()
toplevel.attributes("-toolwindow" , 1)
mainloop()
In this code, when I minimize the main window and open it again, the toplevel window disappears.
Here's an image(GIF) describing my problem:
Is there any way to avoid this?
It would be great if anyone could help me out.
(OS: Windows 10, Python version: 3.9.1, Tkinter version: 8.6)
Upvotes: 0
Views: 449
Reputation: 647
With the help of acw1668, I found the answer by myself.
The top-level window does not disappear; instead, it just goes behind all the windows.
There is a way to bring it back:
from tkinter import *
root = Tk()
root.geometry("500x500")
def bring_window_back(e):
toplevel.attributes('-topmost' , 1)
toplevel.attributes('-topmost' , 0)
toplevel = Toplevel(root)
toplevel.attributes("-toolwindow" , 1)
root.bind("<Map>" , bring_window_back)
mainloop()
Note: The <Map>
binding may not work properly on linux. If you are searching for a solution for this, please see: Binding callbacks to minimize and maximize events in Toplevel windows
Hope this helps you all.
Upvotes: 0
Reputation: 385900
The toolwindow attribute is specifically designed to make the window hide when the root window hides. If you don't want that behavior, don't set that attribute.
Upvotes: 1