Pysimplegui: window.BringToFront() is not working on windows10

Created on 25 Dec 2019  路  8Comments  路  Source: PySimpleGUI/PySimpleGUI

Type of Issues (Enhancement, Error, Bug, Question)

Operating System: windows10

Python version: 3.6

PySimpleGUI Port and Version: Tk

window.BringToFront() doesn't bring application main window in front of other windows applications
this is what i tried with no success:

window.TKroot.lift()  # which is what window.BringToFront() uses
window.TKroot.focus_force()
window.TKroot.grab_set()
window.TKroot.grab_release()

sharing what i tried and works for me:
** using below code make it works and it successfully did bring the application in front of all other windows application

window.TKroot.attributes('-topmost', True)
window.TKroot.attributes('-topmost', False)

https://stackoverflow.com/a/6795115/10146012

Bug Done - Download from GitHub

All 8 comments

Bring to front is not "Keep on top".

Bring to front moves the window to where it is visible. It does not keep it as the topmost application. That's a setting hasn't been exposed. Generally a window is set with keep_on_top=True when the window is created.

In other words, you are able to set the "topmost" flag when the window is created. If you would like to be able to turn it on and off then we an open an enhancement.

bring_to_front isn't doing what I would expect so investigating.

Bring to front is not "Keep on top".

yes i am aware of that, what i meant is BringToFront() doesn't work, the only work around to moves the window to where it is visible is to set topmost attribute temporarely and disable it again

bring_to_front isn't doing what I would expect so investigating.

thanks :+1:

I see from the docstring that there has been trouble in this area before when I wrote it:

    def BringToFront(self):
        """
        Brings this window to the top of all other windows (perhaps may not be brought before a window made to "stay
        on top")
        """

Not sure why I wrote "brought". That should have likely been "called". The only reason I can think that this comment would be there is that it only worked when I tested it on windows that had "Keep on Top" set.

When the window is created with keep_on_top=True then this call to bring_to_font() works as expected. If other windows are in front of it, then it will be moved in front of them.

I didn't do a very good job of documenting this. The way things are at the moment, it only works on window that were created with keep on top set.

I'll experiment with the flipping of topmost attribute as a workaround on Windows and Linux. I assume if it works for those then Mac will likely work as well.

OK, a new implementation for bring_to_front for Windows systems. This appears to be a problem unique to windows. The lift method worked on Linux fine. I'm going to assume the Mac works fine with lift as well for now.

The GitHub version should do what you're looking for.

Thanks a lot :+1: :+1:

Released yesterday to PyPI as version 4.17.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

martinmeteor picture martinmeteor  路  4Comments

yogesh-aggarwal picture yogesh-aggarwal  路  3Comments

ncotrb picture ncotrb  路  4Comments

lucasea777 picture lucasea777  路  3Comments

MikeTheWatchGuy picture MikeTheWatchGuy  路  6Comments