我正在制作一个程序来提醒我 friend 的生日,这样我就不会忘记祝福他们。为此,我制作了两个 tkinter 窗口:
1. First one is for entering name and birth date
2. Second one is for reminding their birthday
我对第二个 tkinter 窗口没有问题,但我想隐藏系统托盘中的第一个 tkinter 窗口,以便它不会在启动时打开,但它确实能够在我像某些程序一样单击程序图标时打开例如:f.lux、Internet Downloader Manager(IDM)、Windows Antivirus 等
为此我已经做了:
root.deiconify()
root.iconify()
几乎解决了问题(但只是几乎)。它隐藏了我的 tkinter 窗口,但在任务栏中显示了我不想要的图标。
我希望隐藏 tkinter 窗口及其图标(从任务栏),但我想在系统托盘中查看 tkinter 窗口图标,以便我可以随时打开程序。
我希望通过隐藏窗口将我的程序显示在此处
我的代码
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/342496.html
关于python - 隐藏系统托盘中的 tkinter 窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54399137/