- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create a System Tray icon of a Tkinter application?
A System Tray icon is used for showing the application’s running state in the taskbar. It typically shows which application is currently running. The system tray icon is visible in the taskbar.
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 the window and provide the icon in 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.
Example
# 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=Tk() win.title("System Tray Application") # Set the size of the window win.geometry("700x350") # Define a function for quit the window def quit_window(icon, item): icon.stop() win.destroy() # Define a function to show the window again def show_window(icon, item): icon.stop() win.after(0,win.deiconify()) # Hide the window and show on the system taskbar def hide_window(): win.withdraw() image=Image.open("favicon.ico") menu=(item('Quit', quit_window), item('Show', show_window)) icon=pystray.Icon("name", image, "My System Tray Icon", menu) icon.run() win.protocol('WM_DELETE_WINDOW', hide_window) win.mainloop()
Output
If you will run the above code, it will display a window.
When we close the window it will still appear in the Taskbar as a System Tray icon.
- Related Articles
- How to make a system tray application in Tkinter?
- How to create a borderless fullscreen application using Python-3 Tkinter?
- How to create a Menu Icon with CSS?
- How to bundle a Python Tkinter application including dependencies?
- How to create a JavaFX Basic Application?
- How to set the tab order in a Tkinter application?
- How to display a tkinter application in fullscreen on macOS?
- Removing the TK icon on a Tkinter window
- How to create a Tkinter toggle button?
- How to create a timer using tkinter?
- How do I change the overall theme of a tkinter application?
- How to create a fixed social media icon bar with CSS?
- How to create a JLabel with an image icon in Java?
- How to create a Button on a Tkinter Canvas?
- How to create Icon Bar with CSS?
