国产成人AV无码一二三区,少女1到100集,国产精品久久久久精品综合紧,巜公妇之诱感肉欲HD在线播放

文章 > Python基础教程 > 如何使用Python 实现秒表功能?

如何使用Python 实现秒表功能?

头像

2020-11-05 15:30:354069浏览 · 0收藏 · 0评论

其实python不是我们看到那么复杂,如果打好扎实的基础,我们可以用python做一些好玩的事情,比如实现秒表功能,一起来看下吧~

前言:

本文的重点是在python中使用Tkinter创建秒表。

关于Tkinter:

Tkinter是Python的标准GUI库。Python与Tkinter结合使用时,提供了一种创建GUI应用程序的快速而简单的方法。Tkinter为Tk GUI工具包提供了一个强大的面向对象接口。Tkinter很容易入门,下面是一些示例代码,可以让您在python中使用Tkinter。

语法:

# Python program to create a
# a new window using Tkinter
# importing the required libraires
import tkinter
  
# creating a object 'top' as instance of class Tk
top = tkinter.Tk()
  
# This will start the blank window
top.mainloop()

输出:

使用Tkinter创建秒表

现在让我们尝试使用Tkinter模块创建一个程序来创建秒表。

所需模块:我们将仅使用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
  
    # 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")
  
# Fixing the window size.
root.minsize(width=250, height=70)
label = Tkinter.Label(root, text="Welcome!", fg="black", font="Verdana 30 bold")
label.pack()
start = Tkinter.Button(root, text='Start',  
width=15, command=lambda:Start(label))
stop = Tkinter.Button(root, text='Stop',  
width=15, state='disabled', command=Stop)
reset = Tkinter.Button(root, text='Reset',
 width=15, state='disabled', command=lambda:Reset(label))
start.pack()
stop.pack()
reset.pack()
root.mainloop()

输出:

好了,以上就是使用Python 实现秒表功能的全部内容了,如需了解更多python实用知识,点击进入PyThon学习网教学中心

关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

戴上自安小玩具调到10档 | 护士小姐| 法国空姐5大结局| 暴躁少女CSGO高清大图特点| 泳装| 美国灭火宝贝3| 《丰满的女邻居》播放| 三个老师轮流给学生布置作业| 麻花MV在线看免费观看电视剧 | 日剧《轮流取珠》| YSL水蜜桃86满十八和88区.| H漫画| 成品网站1688入门怎么样| 两对夫妻同房不交换会影响感情吗 | 韩国神曲| 可切换老司机模式浏览器| 海棠书屋免费无弹窗全文阅读| 第1章饱满的乳峰喷奶水动漫| 我妈妈同意你再做一次心理咨询| 《老板送醉酒丈夫回家》 | 混乱的都市| 公共场合高潮(H)公交车| 男生把小困困放到女生困里视频| 欧美人与人动人物2024心理学| 《父债女偿》在线观看全集| 《艾娃》法国| 土豆| 免费B站在线观看人数在哪儿找到| 《丰满的女邻居》播放| 电影《满足2》完整版在线观看| 俄罗斯大扔子视频观看| 妻子在厨房被三个男人欺负的后果| 哪吒闹海2电影| 妈妈出轨了免费观看电视剧全集| 双色球2025025期开奖结果| 成全在线观看免费完整的| 小扫货几天没弄了| 拍照表情| 年轻的嫂子| 丈夫不在家儿媳想老公的背景故事| 白丝袜精华液抹在脚上的功效