Raspberry Pi+Pyqt:add_event_detect生成Pyqt错误。为什么?

2024-04-25 18:26:31 发布

您现在位置:Python中文网/ 问答频道 /正文

代码如下:

class MyWindowClass(QtGui.QMainWindow, form_class):
       def __init__(self, parent=None):

          GPIO.setmode(GPIO.BOARD) 
          GPIO.setup(26,GPIO.IN)

          QtGui.QMainWindow.__init__(self, parent)
          self.setupUi(self)

          self.alarm_detect()

       def alarm_detect(self):
          getattr(self, "AlarmePerifericos").setVisible(False)

          def alarme_perifericos(channel):
             if not (GPIO.input(channel)):
                 getattr(self, "AlarmePerifericos").setVisible(True)
             else: 
                 getattr(self, "AlarmePerifericos").setVisible(False)

          GPIO.add_event_detect(26, GPIO.BOTH, callback=alarme_perifericos)

app = QtGui.QApplication(sys.argv)
app.setStyle("GTK+") #Changing the style
myWindow = MyWindowClass(None)
myWindow.showFullScreen()
app.exec_()

我正在运行这个PyQt脚本。当程序检测到引脚26时,QObject“AlarmePerifericos”被设置为可见,但我得到错误QCoreApplication::sendPostedEvents: Cannot send posted events for objects in another thread。问题是,正如你所看到的,我不是在另一条线上。是什么造成的?你能帮助我吗?在

谢谢。在


Tags: selfnoneappgpioinitdefclassparent