-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
71 lines (57 loc) · 2.37 KB
/
main.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import random
import sys
from PyQt5 import uic
from PyQt5.QtCore import QSize, QRect, QCoreApplication, QMetaObject
from PyQt5.QtGui import QPainter, QColor, QPen, QBrush, QFont
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.uic.properties import QtCore, QtGui
from pyqt5_plugins.examplebutton import QtWidgets
class Ui_Circles(object):
def setupUi(self, Circles):
Circles.setObjectName("Circles")
Circles.resize(600, 600)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(Circles.sizePolicy().hasHeightForWidth())
Circles.setSizePolicy(sizePolicy)
Circles.setMinimumSize(QSize(600, 600))
Circles.setMaximumSize(QSize(600, 600))
self.pushButton = QtWidgets.QPushButton(Circles)
self.pushButton.setGeometry(QRect(170, 230, 261, 91))
font = QFont()
font.setPointSize(12)
self.pushButton.setFont(font)
self.pushButton.setObjectName("pushButton")
self.retranslateUi(Circles)
QMetaObject.connectSlotsByName(Circles)
def retranslateUi(self, Circles):
_translate = QCoreApplication.translate
Circles.setWindowTitle(_translate("Circles", "Form"))
self.pushButton.setText(_translate("Circles", "Нарисовать случайный круг"))
class Circles(QWidget, Ui_Circles):
def __init__(self):
super().__init__()
self.setupUi(self)
self.circle_coords = None
self.init_ui()
self.show()
def init_ui(self):
self.pushButton.clicked.connect(self.draw)
def draw(self):
self.circle_coords = [random.randrange(0, 500) for i in range(2)]
self.repaint()
def paintEvent(self, event):
if self.circle_coords:
painter = QPainter(self)
painter.begin(self)
diameter = random.randrange(10, 401)
painter.setPen(QPen(QColor(0, 0, 0), 5))
painter.setBrush(QBrush(QColor(*(random.randrange(0, 256) for i in range(3)))))
painter.drawEllipse(*self.circle_coords, diameter, diameter)
painter.end()
self.circle_coords = None
if __name__ == "__main__":
app = QApplication(sys.argv)
window = Circles()
sys.exit(app.exec())