-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
43 lines (33 loc) · 1.06 KB
/
main.py
File metadata and controls
43 lines (33 loc) · 1.06 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
42
43
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.QtGui import QColor, QPainter
from random import randint
from UI import Ui_MainWindow
import sys
class Circle(QMainWindow, Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.do_paint = False
self.pushButton.clicked.connect(self.draw)
def paintEvent(self, event):
if self.do_paint:
qp = QPainter()
qp.begin(self)
self.draw_circle(qp)
qp.end()
self.do_paint = False
def draw(self):
self.do_paint = True
self.update()
def draw_circle(self, qp):
qp.setBrush(QColor(randint(0, 256), randint(0, 256), randint(0, 256)))
self.xy = randint(50, 400)
qp.drawEllipse(300, 100, self.xy, self.xy)
def except_hook(cls, exception, traceback):
sys.__excepthook__(cls, exception, traceback)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Circle()
ex.show()
sys.excepthook = except_hook
sys.exit(app.exec())