import time
from PySide6.QtWidgets import *
from PySide6.QtCore import *
from PySide6.QtGui import *
from page import Ui_Form
import threading
def task(ui):
a=0
while ui.isrunning:
if ui.pausing:
time.sleep(0.02)
continue
ui.data_signal.emit(a)
time.sleep(0.2)
a+=1
if a>100:
break
ui.isrunning = True
class Window(QWidget, Ui_Form):
data_signal = Signal(int)
def __init__(self):
super().__init__()
self.setupUi(self)
self.t:threading.Thread = None
self.data_signal.connect(self.change_value)
self.isrunning = True
self.pausing = False
def onBtnStartClick(self):
if self.t is not None and self.t.is_alive():return
self.t = threading.Thread(target=task,args=(self,),daemon=True)
self.t.start()
def onBtnStopClick(self):
self.isrunning = False
def onBtnPauseClick(self):
self.pausing =True
def onBtnResumeClick(self):
self.pausing = False
def change_value(self,val:int):
self.progressBar.setValue(val)
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
win = Window()
win.show()
sys.exit(app.exec())
承擔因您的行為而導致的法律責任,
本站有權(quán)保留或刪除有爭議評論。
參與本評論即表明您已經(jīng)閱讀并接受
上述條款。