在 PySimpleGUI 中打开 window 顶部显示弹出窗口
show Popup on top of open window in PySimpleGUI
我的 Popup 在当前打开 window 之后打开,所以看不到 Popup。如何在当前打开的 window 之上显示 Popup?
以下是示例代码:
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,但它不起作用,window 获得显示在顶部的优先级,因此 Popup 仍然隐藏在 window 后面。有什么方法可以在 window 上方显示 Popup?
在 Popup 调用中设置保持在顶部为我创建了 window 在顶部。
sg.Popup('Ok clicked', keep_on_top=True)
但是,如果你点击后面的window,因为它也有置顶设置,它会覆盖你的弹窗。
既然你的主window已经被最大化了,那么也许它就不需要保持在最上面了。这将允许您仅在弹出窗口中设置它,以便它确实停留在您的主要 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)
我的 Popup 在当前打开 window 之后打开,所以看不到 Popup。如何在当前打开的 window 之上显示 Popup? 以下是示例代码:
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,但它不起作用,window 获得显示在顶部的优先级,因此 Popup 仍然隐藏在 window 后面。有什么方法可以在 window 上方显示 Popup?
在 Popup 调用中设置保持在顶部为我创建了 window 在顶部。
sg.Popup('Ok clicked', keep_on_top=True)
但是,如果你点击后面的window,因为它也有置顶设置,它会覆盖你的弹窗。
既然你的主window已经被最大化了,那么也许它就不需要保持在最上面了。这将允许您仅在弹出窗口中设置它,以便它确实停留在您的主要 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)