from PyQt5 import QtWidgets, QtCore
import sys
from PyQt5.QtCore import *
import time
class Runthread(QtCore.QThread):
_signal = pyqtSignal(str)
def __init__(self):
super(Runthread, self).__init__()
def __del__(self):
self.wait()
def run(self):
for i in range(100):
time.sleep(0.2)
self._signal.emit(str(i))
class Example(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.button = QtWidgets.QPushButton('开始', self)
self.button.setToolTip('这是一个 <b>QPushButton</b> widget')
self.button.resize(self.button.sizeHint())
self.button.move(120, 80)
self.button.clicked.connect(self.start_login)
self.pbar = QtWidgets.QProgressBar(self)
self.pbar.setGeometry(50, 50, 210, 25)
self.pbar.setValue(0)
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('OmegaXYZ.com')
self.show()
self.thread = None
def start_login(self):
self.thread = Runthread()
self.thread._signal.connect(self.call_backlog)
self.thread.start()
def call_backlog(self, msg):
self.pbar.setValue(int(msg))
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
myshow = Example()
myshow.show()
sys.exit(app.exec_())
文章评论