希望同时使用pysimpleguqt的托盘和窗口



我正在制作一个应用程序,我想在同一时间使用窗口和托盘,但下面的代码需要从窗口首先一个事件,然后它得到托盘的事件,我尝试分别做他们两个线程,但没有运气,

尝试退出,我的意思是从托盘,双击托盘多次,你会看到问题

import PySimpleGUIQt as Sg
for_default = ['a', 'v', 's']
menu_def = ['', ['---', '&p1', ['x', 'y'], '&p2', 'E&xit']]
layout = [[Sg.Text('Default    First     Second')],
[Sg.Listbox(for_default, enable_events=True, key='-DEFAULT-'),
Sg.Listbox(for_default, enable_events=True, key='-FIRST-'),
Sg.Listbox(for_default, enable_events=True, key='-SECOND-')]]
window = Sg.Window('Window Title', layout, finalize=True)
tray = Sg.SystemTray(menu=menu_def)
tray.ShowMessage('My Message', 'The tray icon is up and runnning!')
while True:
event, values, = window.Read()
menu_item = tray.Read()
if menu_item == 'Exit':
print(event)
print(menu_item)
window.hide()
elif menu_item == Sg.EVENT_SYSTEM_TRAY_ICON_DOUBLE_CLICKED:
window.un_hide()
elif event == '-DEFAULT-':
print(event)

找到了一个很好的方法,只需将窗口放入托盘

import PySimpleGUIQt as Sg
for_default = ['a', 'v', 's']
menu_def = ['', ['---', '&p1', ['x', 'y'], '&p2', 'E&xit']]
tray = Sg.SystemTray(menu=menu_def)
tray.ShowMessage('My Message', 'The tray icon is up and runnning!')
while True:
menu_item = tray.Read()
if menu_item == 'Exit':
break
elif menu_item == Sg.EVENT_SYSTEM_TRAY_ICON_DOUBLE_CLICKED:
layout = [[Sg.Text('Default    First     Second')],
[Sg.Listbox(for_default, enable_events=True, key='-DEFAULT-'),
Sg.Listbox(for_default, enable_events=True, key='-FIRST-'),
Sg.Listbox(for_default, enable_events=True, key='-SECOND-')]]
window = Sg.Window('Window Title', layout, finalize=True)
while True:
event, values, = window.Read()
if event == '-DEFAULT-':
print(event)

相关内容

  • 没有找到相关文章

最新更新