How to make a system tray application in Tkinter?

A System Tray application is created for the continuous execution of the program. Whenever an application is closed by the user, it will get its state running on the taskbar. To identify a system tray application, we can provide an image or icon to its application.

To create a System Tray icon of a tkinter application, we can use pystray module in Python. It has many inbuilt functions and methods that can be used to configure the system tray icon of the application.

To install pystray in your machine, you can type "pip install pystray" command in your shell or command prompt.

To create a System Tray icon, you can follow these steps,

  • Import the required libraries - Pystray, Python PIL or Pillow.

  • Define a function hide_window() to withdraw window and provide the icon to the system tray.

  • Add and define two menu items, "Show" and "Quit".

  • Add a Command in the menu items by defining a function for Show and Quit.


# Import the required libraries
from tkinter import *
from pystray import MenuItem as item
import pystray
from PIL import Image, ImageTk

# Create an instance of tkinter frame or window

win.title("System Tray Application")
# Set the size of the window

# Define a function for quit the window
def quit_window(icon, item):

# Define a function to show the window again
def show_window(icon, item):

# Hide the window and show on the system taskbar
def hide_window():
   menu=(item('Quit', quit_window), item('Show', show_window))
   icon=pystray.Icon("name", image, "My System Tray Icon", menu)

win.protocol('WM_DELETE_WINDOW', hide_window)



If you run the above code, it will display the application window.

If we close the window, it will still appear in the taskbar as the system tray application.

Updated on: 19-Jun-2021

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started