通过sg.Window显示提示信息,并按指定键退出。指定键退出可以外部实现。
def showTips():
sg.theme('Dark2')
layout = [[sg.Text('流程录制中')],
[sg.Text('按esc退出')],
[sg.InputText()]]
window = sg.Window('Custom Progress Meter', layout,
finalize=True,
no_titlebar = True,
button_color = 'white',
auto_close = False,
auto_close_duration = None, #5
font = 16,
grab_anywhere = True,
keep_on_top = True,
location = (25, 25),
return_keyboard_events=True #可打印键盘值
)
window.bind("<Escape>", "-ESCAPE-")
while True:
event, values = window.read()
print(event, values)
if event in (sg.WINDOW_CLOSED, "-ESCAPE-"):
break
return True
showTips()
popup
需要显示文本弹窗。
子线程单独执行。
存在问题:子线程创建的方式退出不太稳定,在某些场景下线程销毁失败。
import PySimpleGUI as sg
import time,threading
sg.theme('Dark2') # 设置当前主题
text_lis = ['121', '322']
sg.popup(text_lis[0],text_lis[1],
title = None,
button_color = 'white',
background_color = None,
text_color = None,#'light gray',grey85'white'
button_type = 5,
auto_close = True,
auto_close_duration = None, #5
custom_text = (None, None),
non_blocking = False,
icon = None,
line_width = None,
font = 22,
no_titlebar = True,
grab_anywhere = True,
keep_on_top = True,
location = (100, 100),
relative_location = (None, None),
any_key_closes = True,
image = None,
modal = True)