()
| 27 | |
| 28 | |
| 29 | def main(): |
| 30 | menu = ['', ['---', '!Disabled Item', 'Change Icon', ['Happy', 'Sad', 'Plain'], 'Exit']] |
| 31 | tooltip = 'Tooltip' |
| 32 | |
| 33 | layout = [[sg.T('Empty Window', key='-T-')]] |
| 34 | |
| 35 | window = sg.Window('Window Title', layout, finalize=True, enable_close_attempted_event=True, alpha_channel=0) |
| 36 | window.hide() |
| 37 | |
| 38 | tray = SystemTray(menu, single_click_events=False, window=window, tooltip=tooltip, icon=sg.DEFAULT_BASE64_ICON, key='-TRAY-') |
| 39 | tray.show_message('System Tray', 'System Tray Icon Started!') |
| 40 | print(sg.get_versions()) |
| 41 | while True: |
| 42 | event, values = window.read() |
| 43 | # IMPORTANT step. It's not required, but convenient. Set event to value from tray |
| 44 | # if it's a tray event, change the event variable to be whatever the tray sent |
| 45 | if event == tray.key: |
| 46 | event = values[event] # use the System Tray's event as if was from the window |
| 47 | |
| 48 | if event in (sg.WIN_CLOSED, 'Exit'): |
| 49 | break |
| 50 | |
| 51 | tray.show_message(title=event, message=values) |
| 52 | |
| 53 | if event == 'Happy': |
| 54 | tray.change_icon(sg.EMOJI_BASE64_HAPPY_JOY) |
| 55 | elif event == 'Sad': |
| 56 | tray.change_icon(sg.EMOJI_BASE64_FRUSTRATED) |
| 57 | elif event == 'Plain': |
| 58 | tray.change_icon(sg.DEFAULT_BASE64_ICON) |
| 59 | elif event == 'Hide Icon': |
| 60 | tray.hide_icon() |
| 61 | elif event == 'Show Icon': |
| 62 | tray.show_icon() |
| 63 | elif event == 'Change Tooltip': |
| 64 | tray.set_tooltip(values['-IN-']) |
| 65 | |
| 66 | tray.close() # optional but without a close, the icon may "linger" until moused over |
| 67 | window.close() |
| 68 | |
| 69 | |
| 70 | if __name__ == '__main__': |
no test coverage detected