“我的弹出窗口”在当前打开的窗口后面打开,因此无法看到弹出窗口。如何在当前打开的窗口顶部显示弹出窗口? 以下是示例代码:
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')
我用keep_on_top = True尝试了Popup,但是它不起作用,窗口在顶部显示时优先显示,因此Popup仍然隐藏在窗口后面。有什么方法可以在窗口上方显示弹出窗口?
答案 0 :(得分:2)
在Popup调用中将顶部设置为最上方会为我创建一个窗口。
sg.Popup('Ok clicked', keep_on_top=True)
但是,如果您单击后面的窗口,因为它也位于顶部,因此它将覆盖您的弹出窗口。
由于您的主窗口已被最大化,所以也许不需要将其置顶。这样一来,您就只能在弹出窗口中进行设置,这样它就不会停留在主窗口的顶部。
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)