秒表是一种手持式时计,设计用于测量从激活的特定时间到停用该部件时所经过的时间量。设计用于远距离观看的秒表的大型数字版本,如体育场,被称为秒钟。在手动定时中,时钟由按下按钮的人启动和停止。在全自动时间内,传感器会自动触发启动和停止。
必需的模块:我们只会使用tkinter来创建gui,并且在此程序中不会使用其他库。
# Python program to illustrate a stop watch
# using Tkinter
#importing the required libraries
import
tkinter as Tkinter
counter =
-1
running =
False
def
counter_label(label):
def
count():
if
running:
global
counter
# To manage the intial delay.
if
counter==-1:
display="Starting..."
else:
display=str(counter)
label['text']=display # Or label.config(text=display)
# label.after(arg1, arg2) delays by
# first argument given in milliseconds
# and then calls the function given as second argument.
# Generally like here we need to call the
# function in which it is present repeatedly.
# Delays by 1000ms=1 seconds and call count again.
label.after(1000, count)
counter +=
1
# Triggering the start of the counter.
count()
# start function of the stopwatch
def
Start(label):
global
running
running=True
counter_label(label)
start['state']='disabled'
stop['state']='normal'
reset['state']='normal'
# Stop function of the stopwatch
def
Stop():
global
running
start['state']='normal'
stop['state']='disabled'
reset['state']='normal'
running =
False
# Reset function of the stopwatch
def
Reset(label):
global
counter
counter=-1








暂无数据