2

I am making a program that reminds me birthday of my friends so that I don't forget to wish them. For that I made two two tkinter windows:

1. First one is for entering name and birth date   
2. Second one is for reminding their birthday

I have no problem with second tkinter window but I wanted to hide the first tkinter window in system tray so that it don't open in startup but it do have ability to open whenever I click to the program icon like some programs do eg: f.lux, Internet Downloader Manager(IDM), Windows Antivirus, etc.

For that I have did:

   root.deiconify()

   root.iconify()

which nearly solved by problem (but only nearly). It hid my tkinter window but showed icon in taskbar which I don't want.

I want both tkinter window and its icon hidden (from the taskbar) but I want to view tkinter window icon in system tray so that I can open program anytime I want to.

I want my program to be displayed here by hiding window

SYSTEM TRAY

My CODE

from tkinter import *


def when_clicked(event):
    """function that gets called whenever entry is clicked"""
    if entry_area_two.get() == 'DD-MM':
        entry_area_two.delete(0, "end")  # delete all the text in the entry
        entry_area_two.insert(0, '')  # Insert blank for user input
        entry_area_two.config(fg='black')


def when_not_clicked(event):
    if entry_area_two.get() == '' or entry_area_two.get() == ' ':
        entry_area_two.insert(0, 'DD-MM')
        entry_area_two.config(fg='grey')


def when_clicked_another(event):
    """function that gets called whenever entry is clicked"""
    if entry_area_one.get() == 'Name':
        entry_area_one.delete(0, "end")  # delete all the text in the entry
        entry_area_one.insert(0, '')  # Insert blank for user input
        entry_area_one.config(fg='black')


def when_not_clicked_another(event):
    if entry_area_one.get() == '' or entry_area_one.get() == ' ':
        entry_area_one.insert(0, 'Name')
        entry_area_one.config(fg='grey')


def get():
    name = entry_area_one.get()
    date = entry_area_two.get()

    print(name, date)


def main():
    global entry_area_one
    global entry_area_two

    root = Tk()
    root.resizable(0, 0)

    screen_width = root.winfo_screenwidth()
    screen_height = root.winfo_screenheight()

    tkinter_width, tkinter_height = 300, 280
    pos_x, pos_y = screen_width - 800, screen_height // 5

    root.geometry('{}x{}+{}+{}'.format(tkinter_width, tkinter_height, pos_x, pos_y))

   text_one = Label(root, text='Name')
   text_two = Label(root, text='Date of Birth')

   entry_area_one = Entry(root, bd=2, width=40)
   entry_area_two = Entry(root, bd=2, width=40)

   add_button = Button(root, text='ADD', height=2, width=34, command=get)
   close_button = Button(root, text='CLOSE', height=2, width=34, command=root.destroy)

   text_one.pack()
   text_two.place(x=18, y=80)

   entry_area_one.insert(0, 'Name')
   entry_area_one.bind('<FocusIn>', when_clicked_another)
   entry_area_one.bind('<FocusOut>', when_not_clicked_another)
   entry_area_one.config(fg='grey')
   entry_area_one.pack()

   entry_area_two.insert(0, 'DD-MM')
   entry_area_two.bind('<FocusIn>', when_clicked)
   entry_area_two.bind('<FocusOut>', when_not_clicked)
   entry_area_two.config(fg='grey')
   entry_area_two.place(x=25, y=125)

   add_button.place(x=24, y=170)
   close_button.place(x=24, y=220)

   text_one.config(font=("Courier", 25), fg='Black', bg='grey')
   text_two.config(font=("Courier", 25), fg='Black', bg='grey')

   root.configure(background='grey')
   root.deiconify()   # This didn't worked
   root.iconify()     # This didn't worked
   root.mainloop()

Can I hide my tkinter window in system tray?

Ghantey
  • 626
  • 2
  • 11
  • 25
  • 2
    See also [pystray](https://pypi.org/project/pystray/) – Stop harming Monica Jan 28 '19 at 11:07
  • 2
    This is clearly not an exact duplicate of the linked question since this is specifically about tkinter. The current answer seems sufficient, there is no way. Marking as a duplicate as a way of pointing people towards a similar question seems inappropriate. – AnnanFay Oct 14 '19 at 10:55

1 Answers1

2

As mentioned in this thread, "Tk, the library that Tkinter wraps, does not offer a way to "minimize to taskbar"."

Question: https://mail.python.org/pipermail/python-list/2005-May/295953.html

Answer: https://mail.python.org/pipermail/python-list/2005-May/342496.html

Damian
  • 548
  • 6
  • 14
  • Isn't there any other alternative of doing the same thing ? How do other software do the same thing ? – Ghantey Jan 28 '19 at 09:50
  • 1
    @markkeven maybe `.withdraw()` method of root? As presented here - https://stackoverflow.com/questions/1406145/how-do-i-get-rid-of-python-tkinter-root-window – Damian Jan 28 '19 at 09:54
  • It did the same thing as root.deiconify() root.iconify() did. Can you tell me how do other software minimize in system tray ? – Ghantey Jan 28 '19 at 10:08
  • I don't understand question, you want to know implementation details of low-level Windows interface or alternatives to Tkinter which are supporting minimizing to system tray? – Damian Jan 28 '19 at 10:09
  • Actually yes. I want to know how can I minimize my program to system tray rather than minimizing to taskbar. It would be great if it can be done using tkinter (impossible as you told me). Can you suggest me other package just like tkinter which can solve my problem ? – Ghantey Jan 28 '19 at 10:15
  • Maybe wx.python? This thread shows that it's potentially possible to minimize to tray - https://stackoverflow.com/questions/10233542/wxpython-minimize-a-frame-to-tray but I'm not sure! Please do your own research too and verify it. – Damian Jan 28 '19 at 10:19
  • Thank you very much for helping me out. Thanks a lot – Ghantey Jan 28 '19 at 10:22