欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2067|回復: 0
打印 上一主題 下一主題
收起左側

python寫的跑表程序

[復制鏈接]
跳轉到指定樓層
樓主
用PyCharm 編輯,可以讓大家學習python的多線程
以下是源代碼
import time
import tkinter as tk
from tkinter import *  # Frame use

import threading
import tkinter as tk
import time
import os
import sys

wcmsec = 0
wcsec = 0
wcminutes = 0
wcrun = 0
timegetbk = 0
global t
# ---------main-------------------
if __name__ == '__main__':
    def main():
        global wcrun
        win = tk.Tk()
        win.geometry('350x160')

        win.minsize(350, 160)  # 最小尺寸  python tkinter 設置窗口大小不可縮放
        win.maxsize(350, 160)  # 最大尺寸

        win.wm_attributes('-topmost', 1)  # python tkinter窗口彈出置頂的方法

        win.title("秒表REV2")

        def startwatch():
            global wcrun, timegetbk
            timegetbk = time.time()
            wcrun = 1

        def Resetwatch():
            global wcmsec, wcsec, wcminutes, wcrun
            wcmsec = 0
            wcsec = 0
            wcminutes = 0
            wcrun = 0

            text.delete(1.0, tk.END)
            str1 = "00" + ":" + "00" + ":" + "00"
            text.insert(tk.INSERT, str1)

        def stopwatch():
            global wcrun, timegetbk
            if (wcrun == 1):
                wcrun = 0

            else:
                wcrun = 1

                timegetbk = time.time()

            # time.sleep(0.3)  # 休眠1

        def timecycle():
            global wcmsec, wcsec, wcminutes, wcrun, timegetbk

            # button3.configure(text="--- World!", command=stopwatch)
            if (wcrun == 1):
                win.title("已運行")
                button3.configure(text="停止!", command=stopwatch)
            else:
                win.title("已停止")
                button3.configure(text="運行!", command=stopwatch)

            text.delete(1.0, tk.END)
            win.focus_set()
            if (wcrun > 0):
                timeget = time.time()
                if (timeget > timegetbk):
                    wcmsec = wcmsec + ((timeget - timegetbk) * 1000)
                    timegetbk = time.time()

            if (wcmsec > 999):
                wcmsec = wcmsec - 1000
                wcsec = wcsec + 1
                if (wcsec > 59):
                    wcsec = wcsec - 60
                    wcminutes = wcminutes + 1
                    if (wcminutes > 99):
                        wcminutes = 0

            wcnum = int(wcmsec / 10)
            if (wcnum < 10):
                dispmsec = "0" + str(wcnum)
            else:
                dispmsec = str(wcnum)

            if (wcsec < 10):
                dispsec = "0" + str(wcsec)
            else:
                dispsec = str(wcsec)

            if (wcminutes < 10):
                dispmin = "0" + str(wcminutes)
            else:
                dispmin = str(wcminutes)

            str1 = dispmin + ":" + dispsec + ":" + dispmsec
            text.insert(tk.INSERT, str1)

            #threading.Timer(0.1, timecycle).start()

        def display():
                for i in range(1, 500000):
                    time.sleep(0.1)
              #      print("hello world")
                    timecycle()

            #global t
           # t = threading.Timer(0.1, timecycle)
           # t.start()

        def xFunc1(event):
            if (event.char == "v") or (event.char == "V"):
                startwatch()
            if (event.char == "b") or (event.char == "B"):
                startwatch()
            if (event.char == "n") or (event.char == "N"):
                startwatch()
            if (event.char == " "):
                stopwatch()

        def kill(pid):
            try:
                # command = 'taskkill /F /IM %d' %pid
                # print type(command)
                # os.system(command) #1111
                import subprocess
                subprocess.Popen("cmd.exe /k taskkill /F /T /PID %i" % pid, shell=True)
            except:
                print('no process')

        def on_closing():

            time.sleep(0.1)  # 休眠1
            #t.cancel()  # 關閉線程

            time.sleep(0.1)  # 休眠1
            win.destroy()  # 關閉窗口
            time.sleep(0.1)  # 休眠1
            time.sleep(0.1)  # 休眠1

            pid = os.getpid()
            # os.system('taskkill /f /pid %s' % '20500')
            kill(pid)

            time.sleep(0.1)  # 休眠1
            sys.exit()
            try:
                sys.exit(0)
            except:
                sys.exit(1)

        text = Text(
            master=win,  # 父容器
            bg='pink',  # 背景顏色
            fg='red',  # 文本顏色
            relief='sunken',  # 邊框的3D樣式 flat、sunken、raisedgroove、ridge、solid。
            bd=3,  # 邊框的大小
            width=8,  # 寬度
            height=1,  # 高度
            state='normal',  # 設置狀態 normal、readonly、 disabled
            cursor='arrow',  # 鼠標移動時樣式 arrow, circle, cross, plus...
            font=('黑體', 55),  # 字體
            wrap='char',  # 字數夠width后是否換行 char, none,  word
        )
        text.pack()

        y_setposition = 100
        x_setposition = 20
        x_space_set = 115
        x_position = x_setposition

        # button2 = tk.Button(win, text="啟動", command=startwatch)
        # button2 = tk.Button(win, text="發送版本", command=sw.stopwatch(), width=15, height=5)

        '''
        button2 = tk.Button(win, text="啟動", command=startwatch)
        button2.place(x = x_position,y = y_setposition,width = 80,height = 50)
        '''

        button2 = Button(
            master=win,  # 父容器
            activebackground='red',  # 背景顏色
            activeforeground="white",
            bd="2",
            command=startwatch,
            text="啟動",
            font=('黑體', 22),
        )

        button2.place(x=x_position, y=y_setposition, width=80, height=50)

        button3 = tk.Button(win, text="停止", command=stopwatch)
        x_position = x_setposition + x_space_set
        button3.place(x=x_position, y=y_setposition, width=80, height=50)

        button1 = tk.Button(win, text="復位", command=Resetwatch)
        x_position = x_setposition + x_space_set + x_space_set
        button1.place(x=x_position, y=y_setposition, width=80, height=50)

        win.bind("<Key>", xFunc1)

        global t1
        t1 = threading.Timer(0.1, timecycle())
        t1.start()

        rx1 = threading.Thread(target=display)  # 多線程
        rx1.start()

        win.protocol("WM_DELETE_WINDOW", on_closing)
        win.mainloop()


    main()

#  pyinstaller -F -w main.py   build1
#  pyinstaller -w main.py

stopwatch.png (4.61 KB, 下載次數: 124)

app界面

app界面

評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

無效樓層,該帖已經被刪除
您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表