-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
41 lines (34 loc) · 1.08 KB
/
main.py
File metadata and controls
41 lines (34 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow
from Ui import Ui_MainWindow
from PyQt5.QtGui import QPainter, QColor
from random import randint
import sys
class MyWidget(QMainWindow, Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.setFixedSize(600, 600)
self.do_paint = False
self.button.clicked.connect(self.paint)
def paintEvent(self, event):
if self.do_paint:
self.x = randint(100, 500)
self.y = randint(100, 500)
self.r = randint(1, 90)
qp = QPainter()
qp.begin(self)
self.draw_circle(qp)
qp.end()
def paint(self):
self.do_paint = True
self.repaint()
def draw_circle(self, qp):
self.a = randint(0, 256)
self.b = randint(0, 256)
self.c = randint(0, 256)
qp.setBrush(QColor(self.a, self.b, self.c))
qp.drawEllipse(self.x - self.r, self.y - self.r, self.r, self.r)
app = QApplication(sys.argv)
ex = MyWidget()
ex.show()
sys.exit(app.exec_())