Python 将MQTT与PyQt4集成
我希望运行一个使用PyQt构建的GUI,该GUI包含QLCDNumber,根据对在Pi上运行的MQTT客户机的订阅自动更新。我在集成所需的两段代码时遇到问题。我的GUI在下面 基本上,当主题/速度更新时,我希望GUI上的LCD也更新 提前感谢您的帮助Python 将MQTT与PyQt4集成,python,user-interface,pyqt4,mqtt,Python,User Interface,Pyqt4,Mqtt,我希望运行一个使用PyQt构建的GUI,该GUI包含QLCDNumber,根据对在Pi上运行的MQTT客户机的订阅自动更新。我在集成所需的两段代码时遇到问题。我的GUI在下面 基本上,当主题/速度更新时,我希望GUI上的LCD也更新 提前感谢您的帮助 from PyQt4 import QtGui, QtCore import paho.mqtt.client as mqtt class Window(QtGui.QMainWindow): def __init__(self):
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_())
client.loop\u start()
立即返回,但它对客户端操作也非常重要。如果在调用client.connect()
之后将其移动到,则它应该可以工作。client.loop\u start()
会立即返回,但它对客户端操作也非常重要。如果在调用client.connect()
之后将其移动到,则它应该可以工作