Основная программа:
import serial import time import os import sys import win from win import * from PyQt5 import QtCore, QtGui, QtWidgets class Okno (QtWidgets.QMainWindow): def __init__(self, parent=None): QtWidgets.QWidget.__init__(self, parent) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.ui.pushButton.clicked.connect (self.send) def send (self): dat1 = str(self.ui.lineEdit.text()) print (dat1) ser = serial.Serial('COM2', 9600) data = (bytes(dat1, encoding='ascii')) ser.write (data) s=str(ser.readline()) s=s[3:5] print (s) self.ui.label.setText ("%s" % s) temp = QtCore.pyqtSignal(int) self.temp.connect(self.ui.LcdNumber.display) self.temp.emit(s) app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() okoshko = Okno() okoshko.show() sys.exit(app.exec_())
Не работает эта часть кода:
temp = QtCore.pyqtSignal(int)
self.temp.connect(self.ui.LcdNumber.display)
self.temp.emit(s)
Как правильно выводить на LcdNumber значение переменной s ?
Дизайн:
import sys from PyQt5 import QtCore, QtGui, QtWidgets class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(551, 217) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.pushButton = QtWidgets.QPushButton(self.centralwidget) self.pushButton.setGeometry(QtCore.QRect(380, 20, 111, 61)) self.pushButton.setObjectName("pushButton") self.lcdNumber = QtWidgets.QLCDNumber(self.centralwidget) self.lcdNumber.setGeometry(QtCore.QRect(40, 50, 161, 71)) self.lcdNumber.setObjectName("lcdNumber") self.label = QtWidgets.QLabel(self.centralwidget) self.label.setGeometry(QtCore.QRect(280, 30, 71, 41)) self.label.setObjectName("label") self.label_2 = QtWidgets.QLabel(self.centralwidget) self.label_2.setGeometry(QtCore.QRect(80, 10, 71, 21)) self.label_2.setObjectName("label_2") self.lineEdit = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit.setGeometry(QtCore.QRect(380, 110, 113, 20)) self.lineEdit.setObjectName("lineEdit") MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 551, 21)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) self.pushButton.setText(_translate("MainWindow", "Отправить")) self.label.setText(_translate("MainWindow", "TextLabel")) self.label_2.setText(_translate("MainWindow", "Температура")) if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) MainWindow.show() sys.exit(app.exec_())