2017kamb
2017kamb

Reputation: 242

show Popup on top of open window in PySimpleGUI

My Popup opens behind the current open window, so unable to see the Popup. How to show the Popup on top of the current open window? Following is the sample code:

import PySimpleGUI as sg
# set global options for window
background = '#F0F0F0'
sg.SetOptions(background_color=background, 
    element_background_color=background, 
    text_element_background_color=background,
    window_location=(0, 0), 
    margins=(0,0), 
    text_color = 'Black',
    input_text_color ='Black',
    button_color = ('Black', 'gainsboro'))

layout = [[sg.Button('Ok'), sg.Button('Cancel')]]

window = sg.Window('Test Window', grab_anywhere=False, size=(800, 480), return_keyboard_events=True, keep_on_top=True).Layout(layout).Finalize()

window.Maximize();
while True:             
    event, values = window.read()
    if event in (None, 'Cancel'):
        break
    else:
        sg.Popup('Ok clicked')

I tried Popup with keep_on_top=True but it's not working, window getting priority for show on top so Popup remains hidden behind the window. Is there any way to show Popup above the window?

Upvotes: 5

Views: 21016

Answers (1)

Mike from PSG
Mike from PSG

Reputation: 5764

Setting keep on top in the Popup call created the window on top for me.

        sg.Popup('Ok clicked', keep_on_top=True)

However, if you click on the window behind, because it also has keep on top set, it will cover your popup.

Since your main window is being maximized, then perhaps it does not need keep on top set. This will allow you to only set it on the popup so that it does stay on top of your main window.

import PySimpleGUI as sg
# set global options for window
background = '#F0F0F0'
sg.SetOptions(background_color=background,
    element_background_color=background,
    text_element_background_color=background,
    window_location=(0, 0),
    margins=(0,0),
    text_color = 'Black',
    input_text_color ='Black',
    button_color = ('Black', 'gainsboro'))

layout = [[sg.Button('Ok'), sg.Button('Cancel')]]

window = sg.Window('Test Window', layout, grab_anywhere=False, size=(800, 480), return_keyboard_events=True, finalize=True)

window.Maximize()
window.BringToFront()
while True:
    event, values = window.read()
    if event in (None, 'Cancel'):
        break
    else:
        sg.Popup('Ok clicked', keep_on_top=True)

Upvotes: 8

Related Questions