Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /www/wwwroot/sengshao.com/zb_system/function/c_system_event.php on line 2059

Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /www/wwwroot/sengshao.com/zb_system/function/c_system_event.php on line 2060

Deprecated: Return type of Config::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/wwwroot/sengshao.com/zb_system/function/lib/config.php on line 26

Deprecated: Return type of Config::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/wwwroot/sengshao.com/zb_system/function/lib/config.php on line 36

Deprecated: Return type of Config::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/wwwroot/sengshao.com/zb_system/function/lib/config.php on line 31

Deprecated: Return type of Config::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/wwwroot/sengshao.com/zb_system/function/lib/config.php on line 41

Deprecated: Return type of Config::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/wwwroot/sengshao.com/zb_system/function/lib/config.php on line 17

Deprecated: Constant E_STRICT is deprecated in /www/wwwroot/sengshao.com/zb_system/function/c_system_debug.php on line 80

Deprecated: Constant E_STRICT is deprecated in /www/wwwroot/sengshao.com/zb_system/function/c_system_debug.php on line 80
pyside6 信号和子线程模板 - 僧少博客
当前位置:首页 > 编程 > 正文

pyside6 信号和子线程模板

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()


发表评论


Deprecated: Constant E_STRICT is deprecated in /www/wwwroot/sengshao.com/zb_system/function/c_system_debug.php on line 80