Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minimize the window tkinter in the windows system tray

I made a GUI with Tkinter in python 3. Is it possible to close the window and have the application stays in the Windows System Tray?

Is there any lib or command within Tkinter for this.

like image 787
Ramon Basilio Avatar asked Oct 25 '25 14:10

Ramon Basilio


2 Answers

The entire solution consists of two parts:

  1. hide/restore tkinter window
  2. create/delete systray object

Tkinter has no functionality to work with the system tray.
(root.iconify() minimizes to the taskbar, not to the tray)

step 1) (more info) can be done by

window = tk.Tk()
window.withdraw() # hide
window.deiconify() # show

step 2) can be done by site-packages, e.g. pystray

(an example, the same example, and more info)

like image 129
Александр Avatar answered Oct 27 '25 03:10

Александр


You can use the wm_protocol specifically WM_DELETE_WINDOW protocol. It allows you to register a callback which will be called when the window is destroyed. This is an simple example:

import tkinter as tk

root = tk.Tk()
root.protocol("WM_DELETE_WINDOW", root.iconify)
root.mainloop()

.iconify turns the window into an icon in System Tray.

like image 35
Partho63 Avatar answered Oct 27 '25 03:10

Partho63