python:systray
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
python:systray [2020/08/13 00:55] – Wulf Rajek | python:systray [2023/05/29 11:55] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 2: | Line 2: | ||
https:// | https:// | ||
+ | |||
+ | https:// | ||
+ | |||
+ | https:// | ||
+ | |||
+ | https:// | ||
+ | |||
+ | https:// | ||
+ | https:// | ||
+ | |||
+ | Example: | ||
+ | |||
+ | < | ||
+ | pip install pystray pillow | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | # | ||
+ | #import pystray | ||
+ | from pystray import Icon as icon, Menu as menu, MenuItem as item | ||
+ | from PIL import Image | ||
+ | import os, sys | ||
+ | |||
+ | def action(): | ||
+ | pass | ||
+ | |||
+ | def action_restart(): | ||
+ | """ | ||
+ | | ||
+ | """ | ||
+ | |||
+ | try: | ||
+ | p = psutil.Process(os.getpid()) | ||
+ | for handler in p.get_open_files() + p.connections(): | ||
+ | os.close(handler.fd) | ||
+ | except Exception as e: | ||
+ | # | ||
+ | pass | ||
+ | |||
+ | icon.visible = False | ||
+ | python = sys.executable | ||
+ | os.execl(python, | ||
+ | # | ||
+ | |||
+ | def action_quit(): | ||
+ | icon.visible = False | ||
+ | print(" | ||
+ | os._exit(0) | ||
+ | |||
+ | def launch(): | ||
+ | i = 0; | ||
+ | while i< | ||
+ | print(i) | ||
+ | i += 1 | ||
+ | pass | ||
+ | |||
+ | def resource_path(relative_path): | ||
+ | try: | ||
+ | base_path = sys._MEIPASS | ||
+ | except Exception: | ||
+ | base_path = os.path.abspath(" | ||
+ | |||
+ | return os.path.join(base_path, | ||
+ | |||
+ | image = Image.open(resource_path(" | ||
+ | #icon = pystray.Icon(name ="just text", icon =image, title =" | ||
+ | menu = (item(' | ||
+ | icon = icon(" | ||
+ | |||
+ | def run_call(icon): | ||
+ | if icon is not None: | ||
+ | icon.visible = True | ||
+ | launch() | ||
+ | |||
+ | icon.run(run_call) | ||
+ | </ | ||
+ | |||
+ | Create version file using: | ||
+ | < | ||
+ | pip install pyinstaller_versionfile | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | import pyinstaller_versionfile | ||
+ | |||
+ | pyinstaller_versionfile.create_versionfile( | ||
+ | output_file=" | ||
+ | version=" | ||
+ | company_name=" | ||
+ | file_description=" | ||
+ | internal_name=" | ||
+ | legal_copyright=" | ||
+ | original_filename=" | ||
+ | product_name=" | ||
+ | ) | ||
+ | </ | ||
+ | |||
+ | To build as single file with additional data like images, the resource_path function needs to be included and pyinstaller needs to use the --add-data option. On Windows a semicolon is required, on linux a colon works. | ||
+ | < | ||
+ | wine pyinstaller.exe --onefile --icon=systrayicon.ico --add-data " | ||
+ | </ | ||
+ | |||
+ | Pyinstaller options: | ||
+ | < | ||
+ | --onefile: Creates a single file. Synonyms: -F | ||
+ | --windowed: Ensures that no console is opened during execution. Synonyms: -w and --noconsole | ||
+ | --add-data: adds data to the file using " | ||
+ | --version: adds exe file version information | ||
+ | --icon: adds windows application icon file | ||
+ | </ |
python/systray.1597276515.txt.gz · Last modified: 2023/05/29 11:53 (external edit)