pyqt5 在一个槽函数调用另外一个槽函数(串口工具)

使用全局变量:

class MainCode(QMainWindow, ui.Ui_MainWindow):
def init(self):
QMainWindow.init(self)
ui.Ui_MainWindow.init(self)
self.setupUi(self)

def slot1(self):
global ser
ser = serial.Serial('com42', 57600, timeout=1)
ser.close()
ser.open()
QMessageBox.information(None,'信息','打开串口')

def slot2(self):
global ser
ser.write(b'!^\r\n')
data=ser.readline()
print(data)
ser.close

posted @ 2025-03-23 16:31  Teejiang  阅读(34)  评论(0)    收藏  举报