'Keep TopLevel window in front of main window
I created a TopLevel window that appears in front of my main window when it pops up. It works as intended when I run the program from the command line. The problem occurs when I turn the program into an executable using pyinstaller. Then when the TopLevel window pops up it appears in front of the main window for a brief moment and then moves behind it. To get around this, I'm using toplevel.attributes('-topmost',True)
, but this makes the window stay on top of ALL windows and can't be moved behind them. Why would pyinstaller cause this to happen, and what can I do to get it back to how it worked previously?
Solution 1:[1]
Try top-level.grab_set() with this it will appear on top of the main window and you have to close it before you can work on the window
Solution 2:[2]
This will ensure it always comes to the top
a = TopLevel()
a.lift()
a.attributes('-topmost',True)
a.after_idle(a.attributes,'-topmost',False)
You can also hide your root with
root.withdraw()
Then bring it back with
root.deiconfy()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | AD WAN |
Solution 2 | Jessie Wilson |