在系统托盘中隐藏 tkinter 窗口 [重复]

2024-05-21

我正在制作一个程序来提醒我朋友的生日,这样我就不会忘记祝福他们。为此,我制作了两个 tkinter 窗口:

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

我对第二个 tkinter 窗口没有问题,但我想隐藏系统托盘中的第一个 tkinter 窗口,以便它不会在启动时打开,但每当我像某些程序一样单击程序图标时,它确实能够打开,例如:f .lux、Internet 下载管理器 (IDM)、Windows 防病毒软件等。

为此我做了:

   root.deiconify()

   root.iconify()

这几乎解决了问题(但只是几乎)。它隐藏了我的 tkinter 窗口,但在任务栏中显示了我不想要的图标。

我希望隐藏 tkinter 窗口及其图标(从任务栏),但我想在系统托盘中查看 tkinter 窗口图标,以便我可以随时打开程序。

我希望我的程序通过隐藏窗口显示在这里

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()

我可以在系统托盘中隐藏我的 tkinter 窗口吗?


正如本线程中提到的,“Tk,Tkinter 包装的库,不提供“最小化到任务栏”的方法。”

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

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在系统托盘中隐藏 tkinter 窗口 [重复] 的相关文章