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 |
from gpiozero import LEDBoard,Button from time import sleep from signal import pause #from tkinter import * #此语句不可用,因为Button冲突 import tkinter as tk from tkinter import messagebox button3 = Button(16) button2 = Button(20) button4 = Button(21) button1 = Button(26) leds = LEDBoard(2, 3, 4, 14, 17,27,22,23,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), ] leds.value = M7G[0] #初始值全消隐 lockval = 0 #定义Button的回调函数 def helloButton(): global lockval if button1.is_pressed: if lockval == 0: leds.value = M7G[2] messagebox.showwarning('Python Tkinter', '恭喜!\n1号抢答成功!!!') lockval = 1 elif button2.is_pressed: if lockval == 0: leds.value = M7G[3] lockval = 1 elif button3.is_pressed: if lockval == 0: leds.value = M7G[4] lockval = 1 elif button4.is_pressed: #复位按键 lockval=0 leds.value = M7G[0] #print(button1.value) button1.when_pressed = helloButton button2.when_pressed = helloButton button3.when_pressed = helloButton button4.when_pressed = helloButton root = tk.Tk() root.mainloop() |