0
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:

enter image description here

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)

Lenovo 360
  • 569
  • 1
  • 7
  • 27

2 Answers2

1

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.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • I am using the `-toolwindow` attribute because I want to remove the minimize and maximize option in my toplevel window. If it is the `-toolwindow`attribute that is causing the problem, is there anything else I can do to remove the minimize and maximize options? – Lenovo 360 Feb 18 '21 at 17:36
  • @Lenovo360: you can set the `overrideredirect` flag which will remove the entire titlebar. – Bryan Oakley Feb 18 '21 at 18:02
  • I don't want to remove the whole title bar, instead I only want to remove the minimize and maximize option. Is there any way to achieve this? – Lenovo 360 Feb 18 '21 at 18:07
  • @Lenovo, yes but it probably will be system specific. – Thingamabobs Feb 18 '21 at 18:37
0

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.

Lenovo 360
  • 569
  • 1
  • 7
  • 27