pyqt5, 如何在窗口上显示10个点地循环进度条。

要在PyQt5窗口上显示从1个点逐渐增加到10个点,然后周而复始地循环,可以使用PyQt5的图形绘制功能和定时器来实现。以下是一个简单的例子:

import sys
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtGui import QPainter, QColor, QBrush
from PyQt5.QtCore import Qt, QTimer

class PointDisplay(QWidget):
    def __init__(self):
        super().__init__()
        
        self.points = 1
        self.increment = True
        
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.update_points)
        self.timer.start(1000)  # 1000 milliseconds = 1 second
        
        self.initUI()
        
    def initUI(self):
        self.setGeometry(100, 100, 400, 400)
        self.setWindowTitle('Point Display')
        self.show()
        
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setPen(Qt.NoPen)
        painter.setBrush(QColor(0, 0, 255))  # Blue color
        
        for i in range(self.points):
            x = 50 + 50 * i
            y = 200
            size = 20  # Increase the size of the ellipses
            painter.drawEllipse(x, y, size, size)
        
    def update_points(self):
        if self.increment:
            self.points += 1
            if self.points == 11:  # Reached 10, reset to 1
                self.points = 1
        else:
            self.points -= 1
                
        self.update()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = PointDisplay()
    sys.exit(app.exec_())

定时器的时间间隔可以根据您的需求进行调整,以控制点的增加和减少速度。这只是一个简单的例子,您可以根据您的实际需求进行进一步的定制。

你可能感兴趣的:(python,pyqt,qt,python,开发语言,pyqt)