Python和tkinter
输出创建GUI应用程序和插件的终南捷径。使用创建GUI tkinter
是一项容易的任务。
您只需要使用以下命令来安装 tkinter
apt-get install python-tk python3-tk
对于Fedora用户,请使用以下命令。
dnf install python-tkinter python3-tkinter
这是一个简单的倒计时脚本tkinter
,始终处于顶部和透明状态:
import tkinter as tk
from datetime import datetime, time
def dateDiffInSeconds(date1, date2):
timedelta = date2 - date1
return timedelta.days * 24 * 3600 + timedelta.seconds
def daysHoursMinutesSecondsFromSeconds(seconds):
minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
days, hours = divmod(hours, 24)
return (days, hours, minutes, seconds)
def counter_label(label):
leaving_date = datetime.strptime('2022-01-01 01:00:00', '%Y-%m-%d %H:%M:%S') #end time to count down
def count():
now = datetime.now()
counter = daysHoursMinutesSecondsFromSeconds(dateDiffInSeconds(now, leaving_date))
label.config(text=str("%d days, %d hours, %d minutes, %d seconds" % counter))
label.after(1000, count)
count()
root = tk.Tk()
root.attributes('-topmost', True) #always on top
root.title("Counting Seconds") #title
label = tk.Label(root, fg="dark green") #font color
label.pack()
counter_label(label)
button = tk.Button(root, text='Stop', width=25, command=root.destroy) #stop button
button.pack()
root.wait_visibility(root)
root.wm_attributes('-alpha',0.5) # transparent windows 0.1 - 1
root.mainloop()