0
我是python的新手,我正在努力解決以下問題: 我設計了一個帶有QTDesigner(一些按鈕和一個文本框)的窗體。 將.ui轉換爲.py文件,並將其導入到我的main.py中Python QtDesigner和在Rasper Pi上GPIO事件後的窗體更新
當我按下按鈕時,可變更更新並且文本字段正在更改。 到目前爲止,它工作正常。但是,當我添加一個GPIO事件,其中調用一個函數,該變量也被更改,但Textfield不更新....
我不知道什麼我mak錯誤或問題在哪裏(通過參數?......不同勢線......)
import sys
import RPi.GPIO as GPIO
from PyQt4 import QtGui,QtCore
from display import Ui_MainWindow
entercodestring=""
類主(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_())