python之pyqt5+QProgressBar+statusBar+toolBar+toolButton的结合运用

# -*- coding:utf-8 -*-
'''
pyqt5加QProgressBar加statusBar加toolBar加toolButton
'''
from PyQt5.QtWidgets import QApplication, QWidget, QToolButton, QMainWindow, QProgressBar
from PyQt5.QtCore import Qt
import sys
import time


class my_window(QMainWindow):
    def __init__(self):
        super(my_window, self).__init__()
        self.initUI()
        self.show()

    def initUI(self):
        self.resize(400, 260)
        self.setWindowTitle("给小老弟玩的")
        # self.setGeometry(400, 400, 300, 260)

        # self.toolbar = self.addToolBar("toolBar")
        self.statusBar()

        self.btn_1 = QToolButton(self)
        self.btn_1.setGeometry(5, 5, 100, 30)
        self.btn_1.setText('开始你的表演')
        self.btn_1.setCheckable(True)
        self.btn_1.setChecked(False)
        self.btn_1.setArrowType(Qt.RightArrow)
        self.btn_1.setAutoRaise(True)
        self.btn_1.setToolButtonStyle(Qt.ToolButtonTextOnly)
        self.btn_1.clicked.connect(self.showDetail)
        # self.toolbar.addWidget(self._detailsbutton)
        self.progressBar = QProgressBar(self)
        self.progressBar.setGeometry(20, 100, 350, 20)
        self.progressBar.setMaximum(100)

    def showDetail(self):
        if self.btn_1.isChecked():
            self.statusBar().showMessage("有点耐心,小老弟!")
            self.btn_1.setText('停止')
            for i in range(101):
                self.progressBar.setValue(i)
                time.sleep(0.01)
            self.statusBar().showMessage('点一下停止就回到过去了,小老弟!')
        else:
            self.statusBar().showMessage("If you have any questions, you can tell me on the blog.")
            self.progressBar.reset()
            self.btn_1.setText('开始')


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = my_window()
    sys.exit(app.exec_())

我曾经跨过山和大海,也穿过人山人海,我曾经拥有着的一切,转眼都飘散如烟,我曾经失落失望失掉所有方向,直到看见平凡才是唯一的答案。
——韩寒《平凡之路》

猜你喜欢

转载自blog.csdn.net/shangxiaqiusuo1/article/details/82735550