System Tray Icon for PySimpleGUI (the tkinter version). Adds a system tray icon by using pystray and PIL

Overview

Python GUIs for Humans

psgtray

Add a System Tray Icon to your tkinter port of PySimpleGUI.

psgtray repo

Installation via pip

Installation is via pip:

python -m pip install psgtray

or if you need to upgrade later:

python -m pip install --upgrade --no-cache-dir psgtray

Installation via this repo

You can also download this repo and install it.

  • Download the folder and files
  • From a command prompt:
  • Change to the folder downloaded
  • For Windows type: python setup.py install
  • For other platforms: python3 setup.py install

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.

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.

Release Notes

psgtray 1.0.1 21-Jun-2021

Initial Release

Designed and written by

mike from PySimpleGUI.org

Contributing

Like the PySimpleGUI project, the psgtray project is currently licensed under an open-source license, the project itself is structured like a proprietary product. Pull Requests are not accepted.

License

GNU Lesser General Public License (LGPL 3) +

Copyright

Copyright 2021 PySimpleGUI

You might also like...
Projeto de mini-games de azar com interface gráfica utilizando Python e PySimpleGui.
Projeto de mini-games de azar com interface gráfica utilizando Python e PySimpleGui.

Gambling Mini jogos de azar unidos em uma mesma interface gráfica, utilizando a linguagem de programação Python em conjunto com a biblioteca de interf

Tkinter-ATM - Python GUI case made with Tkinter
Tkinter-ATM - Python GUI case made with Tkinter

tkinter-ATM Python GUI case made with Tkinter The task of this case was to creat

Tkinter calculetor - Tkinter calculetor with python
Tkinter calculetor - Tkinter calculetor with python

Tkinter_calculetor required to run py file pip install tkinter

My Git GUI version made in Python and Tkinter.

Description My Git GUI version made in Python and Tkinter. How to use Basically, create a folder in your computer, open the software, select the path

A really minimalistic operating system made using python's GUI module Tkinter.
A really minimalistic operating system made using python's GUI module Tkinter.

BoxOS V1.0.0 About A really minimalistic operating system made using python's GUI module Tkinter. What seperates it from the other operating systems m

A Python Tkinter based Inventory managment System
A Python Tkinter based Inventory managment System

Inventory Management System Using Python Tkinter Introduction Inventory managemrnt system is an open source platform for manage business. It has a com

Launched in 2018 Actively developed and supported. Supports tkinter, Qt, WxPython, Remi (in browser). Create custom layout GUI's simply.  Python 2.7 & 3 Support. 200+ Demo programs & Cookbook for rapid start. Extensive documentation.  Examples using Machine Learning(GUI, OpenCV Integration,  Chatterbot), Floating Desktop Widgets, Matplotlib + Pyplot integration, add GUI to command line scripts, PDF & Image Viewer. For both beginning and advanced programmers .
A calculator made using Python and Tkinter

Abacus Abacus is a calculator used to compute expressions with the operators of Addition, Subtraction, Multiplication and Division. It is named after

TkArt - A repository created to explore geometry and art creation using TkInter
TkArt - A repository created to explore geometry and art creation using TkInter

tkArt A repository created to explore geometry and art creation using TkInter, a

Comments
  • Demo error?

    Demo error?

    Hello!

    Attempting to run this demo on latest PSG / Windows 10. Wondering is this has just been broken by updates perhaps - Or I'm doing something wrong!

    Error:

    Traceback (most recent call last):
      File "C:\Users\Name\AppData\Local\Programs\Python\Python39\lib\threading.py", line 973, in _bootstrap_inner
        self.run()
      File "C:\Users\Name\AppData\Local\Programs\Python\Python39\lib\threading.py", line 910, in run
        self._target(*self._args, **self._kwargs)
      File "C:\Users\Name\PycharmProjects\_taMain\venv\lib\site-packages\psgtray\psgtray.py", line 181, in _pystray_thread
        self.tray_icon = pystray.Icon(self.title, self._create_image(self.icon))
      File "C:\Users\Name\PycharmProjects\_taMain\venv\lib\site-packages\pystray\_win32.py", line 32, in __init__
        super(Icon, self).__init__(*args, **kwargs)
      File "C:\Users\Name\PycharmProjects\_taMain\venv\lib\site-packages\pystray\_base.py", line 84, in __init__
        self._menu = menu if isinstance(menu, Menu) else Menu(*menu)
    TypeError: pystray._base.Menu() argument after * must be an iterable, not NoneType
    Exception ignored in: <function Icon.__del__ at 0x000001F897F3A940>
    Traceback (most recent call last):
      File "C:\Users\Name\PycharmProjects\_taMain\venv\lib\site-packages\pystray\_win32.py", line 50, in __del__
        if self._running:
    AttributeError: 'Icon' object has no attribute '_running'
    

    Thanks!!!

    opened by eagleEggs 9
  • Reading clicked value without using window object

    Reading clicked value without using window object

    Hi!

    What I want is like a tray.read() that exists in PySimpleGUIQt.

    My app did use Window object in some parts of my app, but most of the time, only the system tray will remain. So, the option of using the window object is not available for me. I am previously on PySimpleGUIQt, so I can do this. I wondering if that tray.read() can only be implemented in this library too.

    Thanks!

    opened by Miracutor 5
  • support PySimpleGui MENU_KEY_SEPARATOR

    support PySimpleGui MENU_KEY_SEPARATOR

    Currently, the tray menu item (plain text) is only support limited PySimpleGui menu symbos (!, ---), key seperator :: was not allowed.

    I add PySimpleGui MENU_KEY_SEPARATOR for tray menu, so we could use style as following:

    tray_menu = ['', ['Show Window', 'Hello::-HELLO-', '!Logs', '---', 'Quit']]
    tray = SystemTray(
        menu=tray_menu,
        tooltip='System Tray With Custom Menu Item Key',
        single_click_events=True,
        window=window,
    )
    

    If we click tray menu item Hello, an event (value: -HELLO-) will be thrown.

    opened by wkyo 1
  • Get left / right click on the tray icon

    Get left / right click on the tray icon

    Hello, I am looking to get a left- /right click on the tray icon so I can create my own window on click. Is there any way to do that without a window being created by psgtray?

    opened by vSteppY 2
Owner
PySimpleGUI
Now Python programmers of all skill levels can make GUI programs. Commercial interests can contact: mike@PySimpleGUI.org
PySimpleGUI
AppQuickLauncher is a tool that can quickly launch apps by clicking the app tray icon.

AppQuickLauncher AppQuickLauncher is a tool that can quickly launch apps by clicking the app tray icon. On Windows 7 or Windows 10, we can add a folde

yin kaisheng 2 Sep 11, 2022
A system tray application written in python that will assist you with your keyboard endeavors.

A system tray application written in python that will assist you with your keyboard endeavors. It has features such as abbreviation, email autofill, media control, writing from clipboard ,typing current date and time etc.

Mach50 1 Dec 15, 2021
Weather-API-GUI-Tkinter - A weather tool made using tkinter which works by fetching query city weather using an API

Weather-API-GUI-Tkinter ☁️ ❄️ version- 1️⃣ . 0️⃣ . 0️⃣ This repo contains a weat

SasiVatsal 4 Jul 8, 2022
Create shortcuts on Windows to your Python, EXE, Batch files or any other file using a GUI made with PySimpleGUI

shor Windows Shortcut Creation Create Windows Shortcuts to your python programs and any other file easily using this application created using PySimpl

PySimpleGUI 7 Nov 16, 2021
GlobalProtectGUI is a simple tray app to connect, disconnect and monitor globalprotect VPN connection.

Simple GlobalProtectGUI GlobalProtectGUI is simple tray app to connect, disconnect and monitor globalprotect VPN connection. Installation Required bef

Aleksandar Dostic 9 Aug 3, 2022
psgresizer - a PySimpleGUI application that will resize your images and BASE64 encode them.

psgresizer A PySimpleGUI Application Resize your images quickly and easily with this GUI application. Resizes and encodes to Base64 so that the result

PySimpleGUI 9 Jul 26, 2022
Tkinter Designer - Create Beautiful Tkinter GUIs by Drag and Drop.

Tkinter Designer is created to speed up and beautify Python GUI Experience. It uses well know design software called Figma. Which makes creating Tkinter GUI in Python a piece of cake.

Parth Jadhav 4.6k Sep 30, 2022
A GUI for designing Python GUI's for PySimpleGUI.

SimpleGUIBuilder A GUI for designing Python GUI's for PySimpleGUI. Installation There is none :) just download the file from a release and run it. Don

Miguel Martins 60 Sep 28, 2022
python+PySimpleGUI+pyserial+threading

GUI_pyserial python+PySimpleGUI+pyserial+threading 功能 1.利用PySimpleGUI制作图形用户界面 2.利用threading实现多线程调用pyserial处理串口通信 模块版本 PySimpleGUI 4.46.0 pyserial 3.5

null 2 Apr 18, 2022
Primeira interface (simples) desenvolvida em Python utilizando o PySimpleGUI

Interface-Python Sobre o projeto Primeira interface gráfica (simples) desenvolvida em Python utilizando o PySimpleGUI Interface Gráfica Tecnologias ut

Matheus Maia Alvarez 5 Apr 9, 2022