1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
from gpiozero import LEDBoard,Button from time import sleep from signal import pause import threading import tkinter as tk from tkinter import messagebox DM = LEDBoard(2, 3, 4, 14, 17,27,22,24,active_high=False) PX = LEDBoard(7,8,9,11,active_high=False) M7G= [ (0, 0, 0, 0, 0,0, 0,0), (1, 1, 1, 1,1, 1,0,0), (0, 1, 1, 0, 0,0, 0,0), (1, 1, 0, 1, 1,0, 1,0), (1, 1, 1, 1,0, 0,1,0), (0, 1, 1, 0,0, 1,1,0), (1, 0, 1, 1,0, 1,1,0), (1, 0, 1, 1,1, 1,1,0), (1, 1, 1, 0,0, 0,0,0), (1, 1, 1, 1,1, 1,1,0), (1, 1, 1, 1,0, 1,1,0), ] Led_Buf =[1,2,3,4] n=0 def fun_timer(): #print('Hello Timer!') global n PX.off()#消隐 DM.value = M7G[Led_Buf[n]+1] if n==2: DM[7].on() PX[n].on() #sleep(1/(75*4))#75HZ n+=1 n&=3 timer = threading.Timer((1/(200*4)), fun_timer)#100hz*4执行一次 timer.start() v=5 def printhello(): #tt.insert(END, "hello") global v try: v=(int)(tt.get('1.0','1.3')) except : wb.set("错误:请输入正确参数") print(v) def fun_timer2(): global v if v>0: Led_Buf[3]-=1 if Led_Buf[3]<0: Led_Buf[3]=9 #v-=1 Led_Buf[0] = v//100%10 Led_Buf[1] = v//10%10 Led_Buf[2] = v%10 else: Led_Buf[3]-=1 elif v==0: #tk.messagebox.showwarning('Python Tkinter', '倒计时时间到!!!') #v=-1 else: pass timer2 = threading.Timer(0.2, fun_timer2) timer2.start() #button3 = Button(16) #button2 = Button(20) #button4 = Button(21) #button1 = Button(26) timer = threading.Timer(1, fun_timer) timer.start() timer2 = threading.Timer(0.1, fun_timer2) timer2.start() root = tk.Tk() tk.Label(root, text="请在下框中输入倒计时时间\n注:其值必须为整数\n点击确定按键启动计时", font=("Helvetica", 16)).pack() tt = tk.Text(root, width = 50, height = 1 ) tt.pack() wb = tk.StringVar() tk.Label(root, textvariable = wb, font=("Helvetica", 8)).pack() root.mainloop() |