How do you make a PyQt5 schedule?



  • How to make a graphic frame that would show the points. And when updated at a certain time, the points were updated.

    введите сюда описание изображения


  • QA Engineer

    One possible solution might look like,

    import sys
    import random
    from PyQt5 import QtCore, QtGui, QtWidgets
    from PyQt5.Qt import *
    from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
    from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
    from matplotlib.figure import Figure
    

    class GraphInit(FigureCanvas):
    def init(self, parent=None):
    fig = Figure()
    self.axes = fig.add_subplot(111, projection="polar")
    self.compute_initial_figure()

        FigureCanvas.__init__(self, fig)
        self.setParent(parent)
    
        FigureCanvas.setSizePolicy(self, QSizePolicy.Expanding, QSizePolicy.Expanding)
        FigureCanvas.updateGeometry(self)
    

    class GraphPopulate(GraphInit):
    def compute_initial_figure(self):
    self.r =[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
    angles = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    self.axes.plot(angles, self.r, 'bo', ms=5)

    def _polar(self):
        self.axes.clear()
        for i in range(20):
            angles = random.choices(range(50), k=10)
            ms = random.randint(1, 7)
            self.axes.plot(angles, self.r, 'bo', ms=ms)
        self.draw()
    

    class GUI(QMainWindow):
    def init(self):
    super().init()
    self.centralwidget = QtWidgets.QWidget()
    self.setCentralWidget(self.centralwidget)
    self.setMinimumSize(QtCore.QSize(270, 270))

        self.widget = QtWidgets.QWidget(self.centralwidget)
        self.sc = GraphPopulate(self.widget)
        self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout.addWidget(self.sc)
        
        self.timer = QTimer()
        self.timer.timeout.connect(self.update_polar)
        self.timer.start(1000)
        
    def update_polar(self):
        self.sc._polar()
    

    if name == 'main':
    app = QApplication(sys.argv)
    w = GUI()
    w.resize(600, 600)
    w.show()
    sys.exit(app.exec_())

    введите сюда описание изображения



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2