pyside6 信号和子线程模板
- 编程
- 2023-02-01
- 822
from PySide6.QtWidgets import QApplication from PySide6.QtUiTools import QUiLoader from threading import Thread from PySide6.QtCore import Signal, QObject import time class MySignals(QObject): # 自定义信号控件 ms_print = Signal(str, str) class MainWindow: def __init__(self): self.ui = QUiLoader().load('my.ui') self.ui.setFixedSize(self.ui.width(), self.ui.height()) self.global_ms = MySignals() # 实例化信号控件 self.global_ms.ms_print.connect(self.update_gui) # 实例化信号控件 self.ui.pushButton.clicked.connect(self.deal) self.ui.pushButton_2.clicked.connect(self.deal_2) def deal(self): def threadFunc(): for i in range(10): self.global_ms.ms_print.emit('bt1', '按钮1被单击%s'%i) time.sleep(1) t = Thread(target=threadFunc) t.start() def deal_2(self): self.global_ms.ms_print.emit('bt2', '按钮2被单机') def update_gui(self, widget, strs): # 界面更新函数 if widget == 'bt1': self.ui.label.setText(strs) elif widget == 'bt2': self.ui.label.setText(strs) app = QApplication([]) window = MainWindow() window.ui.show() app.exec()
上一篇:关于投资--股票 房产
下一篇:小米电视怎么安装应用
发表评论