# Python program to illustrate a stop watch
import tkinter as Tkinter
from datetime import datetime
counter=66600
running=False
def counter_label(label):
def count():
if running:
global counter
# To manage the initial delay.
if counter==66600:
display="Starting..."
else:
tt=datetime.fromtimestamp(counter)
string=tt.strftime("%H:%M:%S")
display=string
label['text']=display
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=66600
# If rest is pressed after pressing stop.
if running == False:
reset['state']='disabled'
label['text']='Welcome!'
# If reset is pressed while the stopwatch is running.
else:
label['text']='Starting...'
root=Tkinter.Tk()
root.title("Stopwatch")
root.iconbitmap("stopwatch.ico")
root.configure(bg="#FFE873")
# Fixing the window size.
root.minsize(width=250,height=70)
label=Tkinter.Label(root,text="Welcome!",fg="#4B8BBE",bg="#FFE873",font="Verdana 30 bold")
label.pack()
f=Tkinter.Frame(root)
start=Tkinter.Button(f,text='Start',width=6,command=lambda:Start(label))
stop=Tkinter.Button(f,text='Stop',width=6,state='disabled',command=Stop)
reset=Tkinter.Button(f,text='Reset',width=6,state='disabled',command=lambda:Reset(label))
f.pack(anchor='center',pady=5)
start.pack(side="left")
stop.pack(side="left")
reset.pack(side="left")
root.mainloop()
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
datetime库是Python中用于处理日期和时间的标准库。它提供了一些类和函数,可以让我们轻松地进行日期和时间的操作。比如,我们可以使用datetime类来表示一个特定的日期和时间,然后进行加减运算、格式化输出等操作。另外,还可以使用timedelta类来表示时间间隔,进行日期和时间的加减运算。在秒表程序中,我们可以利用datetime库来记录开始时间和结束时间,然后计算它们之间的时间差,从而实现秒表功能。具体步骤如下:1. 导入datetime库:`import datetime`2. 获取开始时间:`start_time = datetime.datetime.now()`3. 获取结束时间:`end_time = datetime.datetime.now()`4. 计算时间差:`elapsed_time = end_time - start_time`5. 输出经过的时间`print("Elapsed time:", elapsed_time)`通过以上步骤,我们可以实现一个简单的秒表程序。当用户开始时记录开始时间,结束时记录结束时间,然后计算时间差并输出。这样就可实现秒表
资源推荐
资源详情
资源评论
收起资源包目录
python的datetime库实现的秒表程序样例源代码.zip (3个子文件)
python的datetime库实现的秒表程序样例源代码
counter_watch_output.jpg 16KB
StopWatch.py 2KB
stopwatch.ico 16KB
共 3 条
- 1
资源评论
传奇开心果编程
- 粉丝: 7930
- 资源: 336
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- alu.v
- H21-282学习参考.pdf
- QuestionTwo.java
- QuestionOne.java
- AWS Certified Solutions Architect Study Guide -SAA-C03 .docx
- 校园小情书微信小程序源码 社区小程序前后端开源 校园表白墙交友小程序.rar
- OA办公自动化管理系统(Struts1.2+Hibernate3.0+Spring2+DWR).rar
- 简历-求职简历-word-文件-简历模版免费分享-应届生-高颜值简历模版-个人简历模版-简约大气-大学生在校生-求职-实习
- 南京邮电大学数学实验:熟练掌握 Matlab 软件的基本命令和操作
- 简历-求职简历-word-文件-简历模版免费分享-应届生-高颜值简历模版-个人简历模版-简约大气-大学生在校生-求职-实习
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功