Python 3-将时钟重置为0

时间:2018-08-17 12:17:09

标签: python-3.x tkinter time clock

我有一个获取时间的代码,并在GUI中显示和更新它。

我正在尝试更改代码,以使时间从零开始而不是从计算机获取时间。我试图从计算机上减去从计算机上花费的时间,以使时钟从零开始并递增计数,但这没有用。我正在尝试使其显示运行时间而不是实际时间。

import sys
from tkinter import *
import time
statusbar = Frame(root)
statusbar.pack(side="bottom", fill="x", expand=False)

time1 = ''
clock = Label(root, font=('times', 20, 'bold'), bg='green')

def tick():
    global time1
    # get the current local time from the PC
    time2 = time.strftime('%H:%M:%S')
    # if time string has changed, update it
    if time2 != time1:
        time1 = time2
        clock.config(text=time2)
        # calls itself every 200 milliseconds
        # to update the time display as needed
        # could use >200 ms, but display gets jerky
    clock.after(200, tick)

tick()

status = Label(root, text="Time:", bd=1, relief=SUNKEN, anchor=W)
status.pack(in_=statusbar, side=LEFT, fill=BOTH, expand=True)
clock.pack(in_=statusbar, side=RIGHT, fill=Y, expand=False)


root.mainloop()

0 个答案:

没有答案