升级PYQT GUI中的多个实时传感器



im创建一个GUI(图形用户界面(,该GUI(图形用户界面(读取3个传感器,并将2显示为LCD并绘制另一个。我能够使用所需的元素来创建GUI,并在按下Botton时开始测量。但这仅适用于绘图系统。我无法使其他两个显示器起作用。在简历中,我无法理解更新系统的工作原理。注意,到目前

from PyQt4 import QtCore, QtGui
import pyqtgraph as pg
import random
from math import*
class MainWindow(QtGui.QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.central_widget = QtGui.QStackedWidget()
        self.setCentralWidget(self.central_widget)
        self.login_widget = LoginWidget(self)
        self.login_widget.button.clicked.connect(self.plotter)
        self.central_widget.addWidget(self.login_widget)
    def plotter(self):
        self.data =[0]
        self.start = time.time()
        self.curve = self.login_widget.plot.getPlotItem().plot()
        self.timer = QtCore.QTimer()
        self.timer.timeout.connect(self.updater)
        self.timer.start(0)
    def updater(self):
        self.data.append(self.data[-1]+0.2*(0.5-random.random()))
        self.curve.setData(self.data)
        self.end = time.time()
        self.login_widget.Temperatura.display(self.data[-1])
        self.login_widget.etanol.display(self.end-self.start)
class LoginWidget(QtGui.QWidget):
    def __init__(self, parent=None):
        super(LoginWidget, self).__init__(parent)
        layout = QtGui.QVBoxLayout()
        hbox1 = QtGui.QHBoxLayout()
        hbox2 = QtGui.QHBoxLayout()
        hbox3 = QtGui.QHBoxLayout()
        self.button = QtGui.QPushButton('Start')
        self.button2 = QtGui.QPushButton('Save')
        self.plot = pg.PlotWidget()
        self.setLayout(layout)
        self.Temperatura = QtGui.QLCDNumber(self)
        self.Temperatura.setStyleSheet("QWidget { background-color: rgb(100, 100, 255) }")
        self.etanol = QtGui.QLCDNumber(self)
        self.WindowSize = QtGui.QLabel("Temperature")
        self.SampPts = QtGui.QLabel("% Ethanol")
        layout.addLayout(hbox1)
        hbox1.addWidget(self.button2)
        hbox1.addWidget(self.button)
        layout.addLayout(hbox2)
        hbox2.addWidget(self.WindowSize)
        hbox2.addWidget(self.SampPts)
        layout.addLayout(hbox3)
        hbox3.addWidget(self.Temperatura)
        hbox3.addWidget(self.etanol)
        layout.addWidget(self.plot)
if __name__ == '__main__':
    app = QtGui.QApplication([])
    window = MainWindow()
    window.show()
    app.exec_()

预期的结果是wen i按下按钮所有元素应显示不同的随机数并开始绘制。到现在为止,它只是开始绘制。我不喜欢LCD小部件,如果您知道另一个小部件,请告诉我。

谢谢!

如果您只是尝试将self.data列表中的数据添加到LCD中,则可以将其添加到updater()方法中。

self.login_widget.Temperatura.display(self.data[-1])
self.login_widget.etanol.display((self.data[-1]*100))

如果您想将数据从Arduino发送到Python,请看一下;将数据从Arduino发送到Python

如果这不是所需的结果,请您在要显示的内容上更具体地说明?

有趣的是我会尝试的,但是我要添加3个不同的数据,一个来自一个模拟审查员(加速度计(,这是我不要绘制的,其他2个来自串行,我有一个与传感器相连的Arduino,该传感器测量了燃料中乙醇的温度和百分比。我两个都想在LCD小部件中显示它们。到现在为止,而不是模拟输入一个随机数,而其他2个可以显示Sine或cesine等其他任何东西,但是这些3个元素显示了不同的内容。我将尝试您向我展示的代码行,例如SLEF.DATATEMP和self.dataethanol。如果它可以使用,我会碰到。我之所以使用随机数是因为它让我在eny计算机中执行代码并解决错误,然后我将为自己的内容添加数据。发表评论太久了。谢谢!

最新更新