0

I want to make a script that runs every hour but i don't want the GUI to be visible in taskbar. I don't mind if the GUI is visible when the program is first opened but if the user decides to press the X i want the program to disappear from the taskbar and be visible in the bottom right corner(Skype, discord, ccleaner behaviour)

The GUI is made with tkinter.

How can i do this behaviour? If at all.

1 Answers1

0

To detect if the close button is pressed in tkinter, use the following right before you run root.mainloop()

root.protocol("WM_DELETE_WINDOW", on_closing)

this will call the on_closing function when the user presses the close button, which you can use the following code to make it into a button

root.iconify()

This will minimize it to the taskbar as a button.

Note this will not work on Mac as the window will just be hidden and you will have no way to actually closing it unless killing it manually

so something like this

from tkinter import tk 
root = tk.Tk()
#define widgets and other things here

def on_closing():
    root.iconify()

root.protocol("WM_DELETE_WINDOW", on_closing)
root.mainloop()

If you want it to be on the system tray, tkinter have no support for that, so you'll have to use something like pystray

eroc123
  • 624
  • 1
  • 4
  • 14
  • This doesnt quite solve it. Yes, when X is pressed it the GUI is minimized but i want the tkinter icon to disappear from the taskbar and the icon be visible in the bottom left corner next to the clock. Screenshot with what i mean: https://imgur.com/3jGtiCs As you can see, i have explorer, chrome, firefox and vscode open in taskbar. In the right i have a few more programs running. I want to make my python script like the one on the right. – JohnnyTheHobo Apr 24 '22 at 15:23
  • ah i get what you mean now, but sadly tkinter doesn't support that, so you have to use something like pystray – eroc123 Apr 25 '22 at 05:43