Ramon Basilio
Ramon Basilio

Reputation: 51

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.

Upvotes: 4

Views: 7051

Answers (2)

Александр
Александр

Reputation: 417

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)

Upvotes: 5

Partho63
Partho63

Reputation: 3117

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.

Upvotes: 2

Related Questions