Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将MQTT与PyQt4集成_Python_User Interface_Pyqt4_Mqtt - Fatal编程技术网

Python 将MQTT与PyQt4集成

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):

我希望运行一个使用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):
        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()
之后将其移动到,则它应该可以工作