43 lines
972 B
Python
43 lines
972 B
Python
import sys
|
|
import time
|
|
|
|
from PySide6.QtCore import QThread, Signal, Slot
|
|
from PySide6.QtWidgets import QMainWindow, QApplication, QLineEdit
|
|
|
|
from ui_untitled import Ui_MainWindow
|
|
|
|
|
|
class WorkerThread(QThread):
|
|
# 定义一个信号,用于在计数完成后发送结果到主线程
|
|
result_signal = Signal(int)
|
|
finished = Signal()
|
|
|
|
def run(self):
|
|
count = 0
|
|
for i in range(1, 11):
|
|
count += i
|
|
time.sleep(1) # 模拟耗时操作
|
|
self.result_signal.emit(count)
|
|
# 发射信号
|
|
|
|
self.finished.emit()
|
|
|
|
|
|
class MainWindow(QMainWindow, Ui_MainWindow):
|
|
def __init__(self):
|
|
super(MainWindow, self).__init__()
|
|
self.setupUi(self)
|
|
#self.line = QLineEdit("设置")
|
|
|
|
# self.btn_1.clicked.connect(self.start_count)
|
|
|
|
# 创建并启动后台线程
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app = QApplication(sys.argv)
|
|
win = MainWindow()
|
|
win.show()
|
|
app.exec()
|
|
|