pyside6界面模板 自定义信号更新界面
- 编程
- 2022-08-04
- 1029
from PySide6.QtWidgets import QApplication from PySide6.QtUiTools import QUiLoader from threading import Thread from PySide6.QtCore import Signal, QObject class MySignals(QObject): # 自定义信号控件 ms_print = Signal(str, str) global_ms = MySignals() # 实例化信号控件 class MainWindow: def __init__(self): self.ui = QUiLoader().load('cmd.ui') self.ui.setFixedSize(self.ui.width(), self.ui.height()) self.ui.pushButton.clicked.connect(self.e1) self.ui.pushButton_2.clicked.connect(self.e2) global_ms.ms_print.connect(self.update_gui) # 界面处理 def e1(self): def func_t(): global_ms.ms_print.emit('bt1', 'bt1') t1 = Thread(target=func_t) t1.start() def e2(self): def func_t(): global_ms.ms_print.emit('bt2', 'bt2') t2 = Thread(target=func_t) t2.start() def update_gui(self, widget, strs): # 用一个函数来处理界面的更新 if widget == "bt1": self.ui.plainTextEdit.setPlainText(strs) elif widget == "bt2": self.ui.lineEdit_2.setText(strs) app = QApplication([]) window = MainWindow() window.ui.show() app.exec()
上一篇:怎么学习一个新控件(界面)
下一篇:易语言学习过的命令
发表评论