防止Tkinter按钮排队

时间:2015-02-25 20:32:45

标签: python tkinter

我正在开发一个带有覆盆子pi和2.8英寸电容式触摸屏的小项目。我是python的新手,我需要防止多个按钮按下排队。所需的行为是UI忽略任何按钮按下而前一个按钮正在执行。这是我的代码:

from Tkinter import *
import RPi.GPIO as GPIO
import time

#pin assignments
A=11
B=13
C=15
D=12
E=16
FAN=8

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(A, GPIO.OUT)
GPIO.setup(B, GPIO.OUT)
GPIO.setup(C, GPIO.OUT)
GPIO.setup(D, GPIO.OUT)
GPIO.setup(E, GPIO.OUT)
GPIO.setup(FAN, GPIO.OUT)

class App:
  def fanOn(self):
    GPIO.output(FAN,True)
  def fanOff(self):
    GPIO.output(FAN,False)
  def btnClicked(self,atty):
    GPIO.output(atty,True)
    self.fanOn()
    time.sleep(5)
    GPIO.output(atty,False)
    self.fanOff()
  def __init__(self, master):
    frame = Frame(master)
    frame.pack()
    self.buttonA = Button(frame, text="Fire A", fg="red", command=lambda: self.btnClicked(A))
    self.buttonA.pack(side=LEFT)
    self.buttonB = Button(frame, text="Fire B", fg="red", command=lambda: self.btnClicked(B))
    self.buttonB.pack(side=LEFT)
    self.buttonC = Button(frame, text="Fire C", fg="red", command=lambda: self.btnClicked(C))
    self.buttonC.pack(side=LEFT)
    self.buttonD = Button(frame, text="Fire D", fg="red", command=lambda: self.btnClicked(D))
    self.buttonD.pack(side=LEFT)
    self.buttonE = Button(frame, text="Fire E", fg="red", command=lambda: self.btnClicked(E))
    self.buttonE.pack(side=LEFT)

root = Tk()
app = App(root)
root.mainloop()

感谢您的帮助!

0 个答案:

没有答案