簡體   English   中英

Rasberry Pi上的GPIO事件后,Python QtDesigner和表單更新

[英]Python QtDesigner and Update of Form after GPIO Event on Rasberry Pi

我是python的新手,但我正努力解決以下問題:我使用QTDesigner(某些Buttons和Textfield)設計了一個表單。 將.ui轉換為.py文件,並將其導入到我的main.py中

當我按下一個按鈕時,可更新的內容就會更改,文本字段也會更改。 到目前為止,它工作正常。 但是當我添加一個調用函數的GPIO事件時,變量也被更改,但是Textfield沒有更新。

我不確定我做錯了什么或問題出在哪里(傳遞參數?...不同的線程?...)

import sys
import RPi.GPIO as GPIO
from PyQt4 import QtGui,QtCore
from display import Ui_MainWindow

entercodestring=""

Main(QtGui.QMainWindow)類:

locked=26

def __init__(self):

    GPIO.setmode(GPIO.BCM)
    GPIO.setup(Main.locked, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
    GPIO.add_event_detect(Main.locked,GPIO.RISING, bouncetime = 200, callback = self.buttonEventHandler)

    #GUI
    QtGui.QMainWindow.__init__(self)        
    self.ui = Ui_MainWindow()
    self.ui.setupUi(self)
    self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
    self.ui.pushButton_0.clicked.connect(self.pushButton_0_clicked)
    self.ui.pushButton_1.clicked.connect(self.pushButton_1_clicked)
    self.ui.pushButton_2.clicked.connect(self.pushButton_2_clicked)
    self.ui.pushButton_back.clicked.connect(self.pushButton_back_clicked)


def buttonEventHandler(self,channel):
    global entercodestring
    entercodestring = "Closed"
#Problem is here textDisplay is not showing the new string
    self.textDisplay.setText(entercodestring)

def pushButton_0_clicked(self):
    global entercodestring
    entercodestring = entercodestring + "0"
    self.ui.textDisplay.setText(entercodestring)

def pushButton_1_clicked(self):
    global entercodestring
    entercodestring = entercodestring + "1"
    self.ui.textDisplay.setText(entercodestring)

def pushButton_2_clicked(self):
    global entercodestring
    entercodestring = entercodestring + "2"
    self.ui.textDisplay.setText(entercodestring)


def pushButton_back_clicked(self):
    global entercodestring
    entercodestring = entercodestring[:-1]
    self.ui.textDisplay.setText(entercodestring)

def pushButton_enter_clicked(self):
    sys.exit(app.exec_())

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    window = Main()
    window.show()
    sys.exit(app.exec_())

好的,找到了解決方案。 首先,我需要創建一個pyqt信號並將其發出...。然后可以將這個發出的信號連接到lika一個button_click事件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM