psgtray


Namepsgtray JSON
Version 5.0.0 PyPI version JSON
download
home_pagehttps://github.com/PySimpleGUI/psgtray
SummaryA System Tray Icon that works with the PySimpleGUI tkinter port. Uses pystray to supply the system tray. Works well under Windows.
upload_time2024-02-26 14:24:40
maintainer
docs_urlNone
authorPySimpleSoft Inc.
requires_python>=3.6
licenseFree To Use But Restricted
keywords gui ui pysimplegui tkinter systemtray pystray
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center">
  <p align="center"><img width="238" height="135" src="https://pysimplegui.net/images/logos/psglogofull.svg"><p>

  <h2 align="center">psgtray</h2>
  <h2 align="center">A PySimpleGUI Application</h2>
</p>

Adds ability to run your program in the System Tray using PySimpleGUI tkinter port













## Features

* Adds System Tray Icon
* Adds ability to show messages in system tray
* Show and get menu items from system tray icon
* Provides capability normally only available in the Qt and Wx ports of PySimpleGUI
* Integrates with the pystray python package



## Installation

### Using PIP with PyPI

The latest official release of PySimpleGUI products can be found on PyPI.  To pip install the demo applications from PyPI, use this command

#### If you use the command `python` on your computer to invoke Python (Windows):

`python -m pip install --upgrade psgtray`

#### If you use the command `python3` on your computer to invoke Python (Linux, Mac):

`python3 -m pip install --upgrade psgtray`

### Using PIP with GitHub

You can also pip install the PySimpleGUI Applications that are in the PySimpleGUI GitHub account.  The GitHub versions have bug fixes and new programs/features that have not yet been released to PyPI. To directly pip install from that repo:

#### If you use the command `python` on your computer to invoke Python (Windows):

```bash
python -m pip install --upgrade https://github.com/PySimpleGUI/psgtray/zipball/main
```

#### If you use the command `python3` on your computer to invoke Python (Linux, Mac):

```bash
python3 -m pip install --upgrade https://github.com/PySimpleGUI/psgtray/zipball/main
```

## Adding To Your PySimpleGUI Program

This is a copy of the demo program that can be found in the PySimpleGUI Project's Demo Program folder.

```python
import PySimpleGUI as sg
from psgtray import SystemTray

"""
    A System Tray Icon courtesy of pystray and your friends at PySimpleGUI
    
    Import the SystemTray object with this line of code:
    from psgtray import SystemTray

    Key for the system tray icon is: 
        tray = SystemTray()
        tray.key
        
    values[key] contains the menu item chosen.
    
    One trick employed here is to change the window's event to be the event from the System Tray.
    
    
    Copyright PySimpleGUI 2021
"""

def main():

    menu = ['', ['Show Window', 'Hide Window', '---', '!Disabled Item', 'Change Icon', ['Happy', 'Sad', 'Plain'], 'Exit']]
    tooltip = 'Tooltip'

    layout = [[sg.Text('My PySimpleGUI Celebration Window - X will minimize to tray')],
              [sg.T('Double clip icon to restore or right click and choose Show Window')],
              [sg.T('Icon Tooltip:'), sg.Input(tooltip, key='-IN-', s=(20,1)), sg.B('Change Tooltip')],
              [sg.Multiline(size=(60,10), reroute_stdout=False, reroute_cprint=True, write_only=True, key='-OUT-')],
              [sg.Button('Go'), sg.B('Hide Icon'), sg.B('Show Icon'), sg.B('Hide Window'), sg.Button('Exit')]]

    window = sg.Window('Window Title', layout, finalize=True, enable_close_attempted_event=True)


    tray = SystemTray(menu, single_click_events=False, window=window, tooltip=tooltip, icon=sg.DEFAULT_BASE64_ICON)
    tray.show_message('System Tray', 'System Tray Icon Started!')
    sg.cprint(sg.get_versions())
    while True:
        event, values = window.read()

        # IMPORTANT step. It's not required, but convenient. Set event to value from tray
        # if it's a tray event, change the event variable to be whatever the tray sent
        if event == tray.key:
            sg.cprint(f'System Tray Event = ', values[event], c='white on red')
            event = values[event]       # use the System Tray's event as if was from the window

        if event in (sg.WIN_CLOSED, 'Exit'):
            break

        sg.cprint(event, values)
        tray.show_message(title=event, message=values)

        if event in ('Show Window', sg.EVENT_SYSTEM_TRAY_ICON_DOUBLE_CLICKED):
            window.un_hide()
            window.bring_to_front()
        elif event in ('Hide Window', sg.WIN_CLOSE_ATTEMPTED_EVENT):
            window.hide()
            tray.show_icon()        # if hiding window, better make sure the icon is visible
            # tray.notify('System Tray Item Chosen', f'You chose {event}')
        elif event == 'Happy':
            tray.change_icon(sg.EMOJI_BASE64_HAPPY_JOY)
        elif event == 'Sad':
            tray.change_icon(sg.EMOJI_BASE64_FRUSTRATED)
        elif event == 'Plain':
            tray.change_icon(sg.DEFAULT_BASE64_ICON)
        elif event == 'Hide Icon':
            tray.hide_icon()
        elif event == 'Show Icon':
            tray.show_icon()
        elif event == 'Change Tooltip':
            tray.set_tooltip(values['-IN-'])

    tray.close()            # optional but without a close, the icon may "linger" until moused over
    window.close()

if __name__ == '__main__':
    main()
```

# Limitations

The Windows implementation is working well.  The Linux GTK version, not as well.

Updating the Menu after initial creation is not yet supported.

# Requirements

In order to use this pacakge you'll also need these packages:

* PySimpleGUI
* pystray (licensed under LGPL3)

Currently only versions <= 0.18.0 of pystray are supported

## License & Copyright

Copyright 2023-2024 PySimpleSoft, Inc. and/or its licensors.

This is a free-to-use "Utility" and is licensed under the
PySimpleGUI License Agreement, a copy of which is included in the
license.txt file and also available at https://pysimplegui.com/eula.

Please see Section 1.2 of the license regarding the use of this Utility,
and see https://pysimplegui.com/faq for any questions.


## Contributing

We are happy to receive issues describing bug reports and feature
requests! If your bug report relates to a security vulnerability,
please do not file a public issue, and please instead reach out to us
at issues@PySimpleGUI.com.

We do not accept (and do not wish to receive) contributions of
user-created or third-party code, including patches, pull requests, or
code snippets incorporated into submitted issues. Please do not send
us any such code! Bug reports and feature requests should not include
any source code.

If you nonetheless submit any user-created or third-party code to us,
(1) you assign to us all rights and title in or relating to the code;
and (2) to the extent any such assignment is not fully effective, you
hereby grant to us a royalty-free, perpetual, irrevocable, worldwide,
unlimited, sublicensable, transferrable license under all intellectual
property rights embodied therein or relating thereto, to exploit the
code in any manner we choose, including to incorporate the code into
PySimpleGUI and to redistribute it under any terms at our discretion.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/PySimpleGUI/psgtray",
    "name": "psgtray",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "GUI UI PySimpleGUI tkinter systemtray pystray",
    "author": "PySimpleSoft Inc.",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/32/25/260de04dd2ecdf2042dce8b7173bb485ce7950cbbba5a7d68eca3a34f508/psgtray-5.0.0.tar.gz",
    "platform": null,
    "description": "<p align=\"center\">\r\n  <p align=\"center\"><img width=\"238\" height=\"135\" src=\"https://pysimplegui.net/images/logos/psglogofull.svg\"><p>\r\n\r\n  <h2 align=\"center\">psgtray</h2>\r\n  <h2 align=\"center\">A PySimpleGUI Application</h2>\r\n</p>\r\n\r\nAdds ability to run your program in the System Tray using PySimpleGUI tkinter port\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n## Features\r\n\r\n* Adds System Tray Icon\r\n* Adds ability to show messages in system tray\r\n* Show and get menu items from system tray icon\r\n* Provides capability normally only available in the Qt and Wx ports of PySimpleGUI\r\n* Integrates with the pystray python package\r\n\r\n\r\n\r\n## Installation\r\n\r\n### Using PIP with PyPI\r\n\r\nThe latest official release of PySimpleGUI products can be found on PyPI.  To pip install the demo applications from PyPI, use this command\r\n\r\n#### If you use the command `python` on your computer to invoke Python (Windows):\r\n\r\n`python -m pip install --upgrade psgtray`\r\n\r\n#### If you use the command `python3` on your computer to invoke Python (Linux, Mac):\r\n\r\n`python3 -m pip install --upgrade psgtray`\r\n\r\n### Using PIP with GitHub\r\n\r\nYou can also pip install the PySimpleGUI Applications that are in the PySimpleGUI GitHub account.  The GitHub versions have bug fixes and new programs/features that have not yet been released to PyPI. To directly pip install from that repo:\r\n\r\n#### If you use the command `python` on your computer to invoke Python (Windows):\r\n\r\n```bash\r\npython -m pip install --upgrade https://github.com/PySimpleGUI/psgtray/zipball/main\r\n```\r\n\r\n#### If you use the command `python3` on your computer to invoke Python (Linux, Mac):\r\n\r\n```bash\r\npython3 -m pip install --upgrade https://github.com/PySimpleGUI/psgtray/zipball/main\r\n```\r\n\r\n## Adding To Your PySimpleGUI Program\r\n\r\nThis is a copy of the demo program that can be found in the PySimpleGUI Project's Demo Program folder.\r\n\r\n```python\r\nimport PySimpleGUI as sg\r\nfrom psgtray import SystemTray\r\n\r\n\"\"\"\r\n    A System Tray Icon courtesy of pystray and your friends at PySimpleGUI\r\n    \r\n    Import the SystemTray object with this line of code:\r\n    from psgtray import SystemTray\r\n\r\n    Key for the system tray icon is: \r\n        tray = SystemTray()\r\n        tray.key\r\n        \r\n    values[key] contains the menu item chosen.\r\n    \r\n    One trick employed here is to change the window's event to be the event from the System Tray.\r\n    \r\n    \r\n    Copyright PySimpleGUI 2021\r\n\"\"\"\r\n\r\ndef main():\r\n\r\n    menu = ['', ['Show Window', 'Hide Window', '---', '!Disabled Item', 'Change Icon', ['Happy', 'Sad', 'Plain'], 'Exit']]\r\n    tooltip = 'Tooltip'\r\n\r\n    layout = [[sg.Text('My PySimpleGUI Celebration Window - X will minimize to tray')],\r\n              [sg.T('Double clip icon to restore or right click and choose Show Window')],\r\n              [sg.T('Icon Tooltip:'), sg.Input(tooltip, key='-IN-', s=(20,1)), sg.B('Change Tooltip')],\r\n              [sg.Multiline(size=(60,10), reroute_stdout=False, reroute_cprint=True, write_only=True, key='-OUT-')],\r\n              [sg.Button('Go'), sg.B('Hide Icon'), sg.B('Show Icon'), sg.B('Hide Window'), sg.Button('Exit')]]\r\n\r\n    window = sg.Window('Window Title', layout, finalize=True, enable_close_attempted_event=True)\r\n\r\n\r\n    tray = SystemTray(menu, single_click_events=False, window=window, tooltip=tooltip, icon=sg.DEFAULT_BASE64_ICON)\r\n    tray.show_message('System Tray', 'System Tray Icon Started!')\r\n    sg.cprint(sg.get_versions())\r\n    while True:\r\n        event, values = window.read()\r\n\r\n        # IMPORTANT step. It's not required, but convenient. Set event to value from tray\r\n        # if it's a tray event, change the event variable to be whatever the tray sent\r\n        if event == tray.key:\r\n            sg.cprint(f'System Tray Event = ', values[event], c='white on red')\r\n            event = values[event]       # use the System Tray's event as if was from the window\r\n\r\n        if event in (sg.WIN_CLOSED, 'Exit'):\r\n            break\r\n\r\n        sg.cprint(event, values)\r\n        tray.show_message(title=event, message=values)\r\n\r\n        if event in ('Show Window', sg.EVENT_SYSTEM_TRAY_ICON_DOUBLE_CLICKED):\r\n            window.un_hide()\r\n            window.bring_to_front()\r\n        elif event in ('Hide Window', sg.WIN_CLOSE_ATTEMPTED_EVENT):\r\n            window.hide()\r\n            tray.show_icon()        # if hiding window, better make sure the icon is visible\r\n            # tray.notify('System Tray Item Chosen', f'You chose {event}')\r\n        elif event == 'Happy':\r\n            tray.change_icon(sg.EMOJI_BASE64_HAPPY_JOY)\r\n        elif event == 'Sad':\r\n            tray.change_icon(sg.EMOJI_BASE64_FRUSTRATED)\r\n        elif event == 'Plain':\r\n            tray.change_icon(sg.DEFAULT_BASE64_ICON)\r\n        elif event == 'Hide Icon':\r\n            tray.hide_icon()\r\n        elif event == 'Show Icon':\r\n            tray.show_icon()\r\n        elif event == 'Change Tooltip':\r\n            tray.set_tooltip(values['-IN-'])\r\n\r\n    tray.close()            # optional but without a close, the icon may \"linger\" until moused over\r\n    window.close()\r\n\r\nif __name__ == '__main__':\r\n    main()\r\n```\r\n\r\n# Limitations\r\n\r\nThe Windows implementation is working well.  The Linux GTK version, not as well.\r\n\r\nUpdating the Menu after initial creation is not yet supported.\r\n\r\n# Requirements\r\n\r\nIn order to use this pacakge you'll also need these packages:\r\n\r\n* PySimpleGUI\r\n* pystray (licensed under LGPL3)\r\n\r\nCurrently only versions <= 0.18.0 of pystray are supported\r\n\r\n## License & Copyright\r\n\r\nCopyright 2023-2024 PySimpleSoft, Inc. and/or its licensors.\r\n\r\nThis is a free-to-use \"Utility\" and is licensed under the\r\nPySimpleGUI License Agreement, a copy of which is included in the\r\nlicense.txt file and also available at https://pysimplegui.com/eula.\r\n\r\nPlease see Section 1.2 of the license regarding the use of this Utility,\r\nand see https://pysimplegui.com/faq for any questions.\r\n\r\n\r\n## Contributing\r\n\r\nWe are happy to receive issues describing bug reports and feature\r\nrequests! If your bug report relates to a security vulnerability,\r\nplease do not file a public issue, and please instead reach out to us\r\nat issues@PySimpleGUI.com.\r\n\r\nWe do not accept (and do not wish to receive) contributions of\r\nuser-created or third-party code, including patches, pull requests, or\r\ncode snippets incorporated into submitted issues. Please do not send\r\nus any such code! Bug reports and feature requests should not include\r\nany source code.\r\n\r\nIf you nonetheless submit any user-created or third-party code to us,\r\n(1) you assign to us all rights and title in or relating to the code;\r\nand (2) to the extent any such assignment is not fully effective, you\r\nhereby grant to us a royalty-free, perpetual, irrevocable, worldwide,\r\nunlimited, sublicensable, transferrable license under all intellectual\r\nproperty rights embodied therein or relating thereto, to exploit the\r\ncode in any manner we choose, including to incorporate the code into\r\nPySimpleGUI and to redistribute it under any terms at our discretion.\r\n",
    "bugtrack_url": null,
    "license": "Free To Use But Restricted",
    "summary": "A System Tray Icon that works with the PySimpleGUI tkinter port.  Uses pystray to supply the system tray.  Works well under Windows.",
    "version": "5.0.0",
    "project_urls": {
        "Homepage": "https://github.com/PySimpleGUI/psgtray"
    },
    "split_keywords": [
        "gui",
        "ui",
        "pysimplegui",
        "tkinter",
        "systemtray",
        "pystray"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1e2dcb472aab614886dcd2532446a6f1b2aad81d36340b614f40e641700f2eda",
                "md5": "c5817c1f396499edfdf00250e6949d1d",
                "sha256": "070f45a4e22c463643a40f069d19209d500696a1aabde1fef5adabc2f9c15bcd"
            },
            "downloads": -1,
            "filename": "psgtray-5.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c5817c1f396499edfdf00250e6949d1d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 37592,
            "upload_time": "2024-02-26T14:24:29",
            "upload_time_iso_8601": "2024-02-26T14:24:29.218614Z",
            "url": "https://files.pythonhosted.org/packages/1e/2d/cb472aab614886dcd2532446a6f1b2aad81d36340b614f40e641700f2eda/psgtray-5.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3225260de04dd2ecdf2042dce8b7173bb485ce7950cbbba5a7d68eca3a34f508",
                "md5": "7988c328d18bc6cbf8c18b7a9fc98503",
                "sha256": "8f2178ff51ffa24818645ebe8b48fc2183a010c7c447f277df6275c38e7def4c"
            },
            "downloads": -1,
            "filename": "psgtray-5.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "7988c328d18bc6cbf8c18b7a9fc98503",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 37055,
            "upload_time": "2024-02-26T14:24:40",
            "upload_time_iso_8601": "2024-02-26T14:24:40.481898Z",
            "url": "https://files.pythonhosted.org/packages/32/25/260de04dd2ecdf2042dce8b7173bb485ce7950cbbba5a7d68eca3a34f508/psgtray-5.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-26 14:24:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "PySimpleGUI",
    "github_project": "psgtray",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "psgtray"
}
        
Elapsed time: 0.18067s