1
私はPiで動作するMQTTクライアントへのサブスクリプションに基づいて自動的に更新するQLCDNumberを含むPyQtを使用して構築されたGUIを実行したいと考えています。私は必要なコードの2つのセクションを統合するのに問題があります。私のGUIは以下の通りです。PyQt4とのMQTTの統合
基本的には、トピックの更新/速度の更新時にGUIのLCDも更新したいと思っています。
ありがとうございました!
from PyQt4 import QtGui, QtCore
import paho.mqtt.client as mqtt
class Window(QtGui.QMainWindow):
def __init__(self):
super(Window, self).__init__()
self.setGeometry(50,50,500,500)
self.setWindowTitle("Think Physics: Technology Wishing Well")
self.home()
def home(self):
mqttLCD = QtGui.QLCDNumber(self)
mqttLCD.setNumDigits(1)
client.connect('localhost', 1883)
self.show()
def on_connect(self, client, userdata, rc):
print "Connected with result code: " + str(rc)
client.subscribe("wishing/speed")
def on_message(self, client, userdata, msg):
print "Topic: ", msg.topic + '\nMessage: ' + msg.payload
mqttLCD.display(msg.payload)
if __name__ == "__main__":
import sys
global client = mqtt.Client()
app = QtGui.QApplication(sys.argv)
GUI = Window()
Window.show()
client.loop_start()
sys.exit(app.exec_())