其他分享
首页 > 其他分享> > 一个简单的进度条

一个简单的进度条

作者:互联网

from PySide2.QtWidgets import QApplication, QWidget, QPushButton, QProgressBar, QVBoxLayout
from PySide2.QtCore import QThread, Slot, Signal
import time

class myThread(QThread):
change_value = Signal(int)

def run(self):
ct = 0
while ct < 100:
ct += 1
time.sleep(0.3)
self.change_value.emit(ct)


class MyWidget(QWidget):
def __init__(self):
super(MyWidget, self).__init__()
self.setGeometry( 500, 500, 650, 450)
self.setWindowTitle("My Progress bar")
self.initUI()
self.show()

def initUI(self):
self.pgb = QProgressBar()
self.startButn = QPushButton("Start")
self.startButn.clicked.connect(self.startProgressBar)

vbox = QVBoxLayout()
vbox.addWidget(self.pgb)
vbox.addWidget(self.startButn)
self.setLayout(vbox)

def startProgressBar(self):
self.thread = myThread()
self.thread.change_value.connect(self.setProgressVal)
self.thread.start()

def setProgressVal(self, val):
self.pgb.setValue(val)



if __name__ == "__main__":
app = QApplication([])
widget = MyWidget()
#widget.show()

app.exit(app.exec_())

标签:__,pgb,进度条,一个,self,vbox,简单,def,ct
来源: https://www.cnblogs.com/TadGuo/p/15831618.html