question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Windows 7 - dialog boxes spawn behind other windows.

See original GitHub issue

(Cross posting from http://stackoverflow.com/questions/31223583/easygui-dialogs-are-not-given-focus-when-created .)

I am using Python 2.7.9, easygui 0.97.4, and Windows 7.

I am trying to pop up a dialog box using the following:

import easygui
easygui.msgbox()

I would expect a dialog box to pop up and come to the foreground, taking focus. Sometimes, this happens. Other times, the dialog box does not come to the front, and spawns behind all other windows.

Whether the dialog box comes to the front, or hides behind other windows, seems to depend on something unpredictable. Giving different arguments to easygui.msgbox() doesn’t seem to help. Restarting the Python interpreter sometimes makes it work, and sometimes doesn’t.

The issue is not so bad for simple dialogs, which at least give a flashing button in the task bar to get your attention.

enter image description here

It is worse for diropenbox() which does not spawn a flashing button in the taskbar. The dialog spawns behind a window and gives no evidence it’s there, until you minimise all other windows.

enter image description here

enter image description here

Is this normal and expected behaviour? I would like easygui dialogs to always come to the front and always take focus, instead of hiding behind other windows.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
ProsperousHeartcommented, Feb 25, 2022

This is still an issue. Windows 10, python 3.10

1reaction
blipkcommented, Jan 12, 2022

This is still happening on windows 10.

A hackish workaround if anyone happens to be looking for this:

import ctypes
import win32gui
import win32con
from pywinauto.findwindows    import find_window

def show_window(title):
    if os.name != 'nt': return
    time.sleep(0.25)
    window = None
    done = False
    attempts = 0
    print("Searching for window with title:", title)
    while not done:
        attempts += 1
        if attempts > 50: break
        try:
            window = find_window(best_match=title)
        except:
            window = None
            continue
        if window:
            print("Found window", window)
            try:
                win32gui.SetWindowPos(window, win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_SHOWWINDOW | win32con.SWP_NOMOVE | win32con.SWP_NOREPOSITION | win32con.SWP_NOSIZE)
                win32gui.SetForegroundWindow(window)
                done = True
                print("Window set to foreground")
                return True
            except Exception as e:
                print("Error bringing window to front", e)
                continue
    print("Search done with no result....")
    return False
t = threading.Thread(target=show_window,name='WindowFocus',args=['Select a video'])
t.daemon = True
t.start()
chosen = easygui.fileopenbox(default=target+'\\*.webm', title="Select a video", filetypes=[['*.mp4', '*.webm', 'Videos']])
Read more comments on GitHub >

github_iconTop Results From Across the Web

Dialog box on many programs appears behind the main ...
One of the biggest problems for me is creating a contact in Outlook, the box to fill in the information appears behind all...
Read more >
Remote App, Printer properties opens behind redirect dialog box
We noticed an issue in July 2013 with all redirect printers using RemoteApps on Server 2008R2. When you clicl on File>Print and sleclt ......
Read more >
Active window & dialog box beneath inactives.
Sometimes active window or dialog box is behind inactive window. The active window cannot be brought to the front. The dialog box can...
Read more >
All my dialog boxes are hidden behind parent window
It should bring up one or more thumbnails of instances/documents open for that application. Hover your mouse over the thumbnail of the instance/ ......
Read more >
Fix File Dialog prompts not spawning in the foreground in ...
Fix File Dialog prompts not spawning in the foreground in Windows 10 · Tap on the Windows-key, type regedit, and select the result....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found