import sys
from PyQt5.QtCore import Qt
import numpy as np
import threading
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setGeometry(300, 300, 400, 400)
self.setWindowTitle('Rect')
self.show()
def paintEvent(self, e):
qp.begin(self)
self.draw_rect(qp)
e = threading.Event()
#the part of a problem
while not e.wait(1):
self.update()
qp.end()
def draw_rect(self, qp):
for i in range(5):
rand_x = 100 * np.random.randn()
rand_y = 100 * np.random.randn()
qp.drawRect(self.width() / 2 + rand_x, self.height() / 2 + rand_y, 10, 10)
if __name__ == '__main__':
ex = MyApp()
sys.exit(app.exec_())
import sys
from PyQt5.QtWidgets import QWidget, QApplication , QPushButton, QVBoxLayout
from PyQt5.QtGui import QPainter, QPen, QColor, QBrush
from PyQt5.QtCore import Qt
import numpy as np
import threading
class MyApp(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setGeometry(300, 300, 400, 400)
self.setWindowTitle('Rect')
self.show()
def paintEvent(self, e):
qp = QPainter()
qp.begin(self)
self.draw_rect(qp)
e = threading.Event()
#the part of a problem
while not e.wait(1):
self.update()
qp.end()
def draw_rect(self, qp):
qp.setBrush(QColor(0, 0, 0))
for i in range(5):
rand_x = 100 * np.random.randn()
rand_y = 100 * np.random.randn()
qp.drawRect(self.width() / 2 + rand_x, self.height() / 2 + rand_y, 10, 10)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MyApp()
sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode
Bookmarks