Skip to content

Instantly share code, notes, and snippets.

@andy23512
Created May 9, 2020 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andy23512/a92ea0ad8cfa9b7714caafaed006a14b to your computer and use it in GitHub Desktop.
Save andy23512/a92ea0ad8cfa9b7714caafaed006a14b to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel
from PyQt5.QtGui import QPainter, QPen
from PyQt5.QtCore import QTimer, Qt
class MainWindow(QMainWindow):
# constructor
def __init__(self):
QMainWindow.__init__(self)
# counter
self.i = 0
self.width = 500
self.height = 500
self.setGeometry(0, 0, self.width, self.height)
# make QTimer
self.qTimer = QTimer()
# set interval to 1 s
self.qTimer.setInterval(1000) # 1000 ms = 1 s
# connect timeout signal to signal handler
self.qTimer.timeout.connect(self.updateCount)
# start timer
self.qTimer.start()
def updateCount(self):
self.i += 1
self.update()
def paintEvent(self, event):
painter = QPainter(self)
painter.setPen(QPen(Qt.green, 8, Qt.DashLine))
for i in range(self.i):
painter.drawEllipse(40 + i * 50, 40, 400, 400)
qApp = QApplication(sys.argv)
# setup GUI
qWin = MainWindow()
qWin.show()
# run application
sys.exit(qApp.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment