日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:如何使用Python實現(xiàn)秒表功能?

其實python不是我們看到那么復雜,如果打好扎實的基礎,我們可以用python做一些好玩的事情,比如實現(xiàn)秒表功能,一起來看下吧~

前言:

本文的重點是在python中使用Tkinter創(chuàng)建秒表。

關于Tkinter:

Tkinter是Python的標準GUI庫。Python與Tkinter結合使用時,提供了一種創(chuàng)建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創(chuàng)建秒表

現(xiàn)在讓我們嘗試使用Tkinter模塊創(chuàng)建一個程序來創(chuàng)建秒表。

所需模塊:我們將僅使用tkinter來創(chuàng)建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 實現(xiàn)秒表功能的全部內(nèi)容了,如需了解更多python實用知識,點擊進入PyThon學習網(wǎng)教學中心。


當前題目:創(chuàng)新互聯(lián)Python教程:如何使用Python實現(xiàn)秒表功能?
URL鏈接:http://m.5511xx.com/article/coeogih.html