韩漫免费漫画在线观看方法,《好好疼爱里面》免费看,年轻漂亮的女士护士内衣,妈妈醉酒后把我当爸爸电视剧

文章 > 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学习网教学中心

关注

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

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

.动漫《纯洁的修女》在线看| 欧美大片免费PPT| 黑丝| 男生女生拆拆很痛的轮滑鞋免费下. | 人与狗胶配方大全高清视频| 天美麻花星空免费观看电视1| AGV亚洲版和欧洲版买哪个| 憋尿白丝小肚子凸起高冷知乎| 一个鸡蛋的热量是多少大卡| 极品女教师| 健身教练压腿压进去会怎么样| 美女比基尼| 把老婆闺蜜干了俩次| 法国色情《宝贝宝贝3| 泰国电影《初次深交流》| 欧美大片| 按摩师把我添高潮了6次| 我在开会他在下添好爽| 出门忘穿胸罩乳头凸起怎么办 | B站暴躁女RAPPER| 男牛把小困困放到女生困里视频 | 女孩蹲下小便视频大全| 母亲和女婿免费高清电视剧 | 学校停电被同桌C了3次| 学校停电被同桌C了3次| 儿媳的报复(公媳)(一颗发财树..| 欧美寡妇性猛交XXX| 偷偷在线观看免费高清电视剧推荐| 女人被添荫蒂舒服了| 《男医生的特殊治疗》| 美女两个球球抖动抓球球视频| 日日精进久久为功的下一句是| 欧美一区| 三年大片免费观看完整版高清| 《性爽2》电影| 《巨大荫蒂》免费| 偏偏宠爰| 女性LOGO大全图片| 英语班长乖乖挽起裙子怎么| 妈妈的绣感| 老翁玩嫩媳