- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 make Tkinter Window appear in the taskbar?
A System Tray application is always created on the taskbar. 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 the 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 the steps given below −
Import the required libraries − Pystray, Python PIL or Pillow.
Define a function hide_window() to withdraw the 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=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("image.ico") menu=(item('Quit', quit_window), item('Show', show_window)) icon=pystray.Icon("name", image, "title", menu) icon.run() win.protocol('WM_DELETE_WINDOW', hide_window) win.mainloop()
If we run the above code, it will display the application window with some widgets and elements in it.
If we close the window, it will display the window icon in the taskbar menu.
- How to make a Tkinter window jump to the front?
- How to make a Tkinter window not resizable?
- How to draw images in the Tkinter window?
- How to keep the window focus on the new Toplevel() window in Tkinter?
- Function to close the window in Tkinter
- How to show webcam in TkInter Window?
- Tkinter-How to get the current date to display in a tkinter window?
- How to put a Toplevel window in front of the main window in Tkinter?
- How to center a window on the screen in Tkinter?
- How to close only the TopLevel window in Python Tkinter?
- How to bind the Enter key to a tkinter window?
- How to control automated window resizing in Tkinter?
- How to resize the background image to window size in Tkinter?
- How can I resize the root window in Tkinter?
- How to delete Tkinter widgets from a window?