我正在制作一个程序,使我想起朋友的生日,这样我就不会忘记希望他们。为此,我制作了两个两个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窗口隐藏在系统托盘中吗?
答案 0 :(得分:1)
如该线程中所述,“ Tkinter包装的库Tk没有提供“最小化任务栏”的方法。”
问题:https://mail.python.org/pipermail/python-list/2005-May/295953.html
答案:https://mail.python.org/pipermail/python-list/2005-May/342496.html