Ejemplo n.º 1
0
class Example(QWidget):
    def __init__(self, *args):
        super().__init__()
        super(MainWindow, self).__init__(*args)
        self.setupUi(self)
        self.btn.clicked.connect(self.draw())
        self.qp = QPainter()

    def paint(self):
        self.qp.repaint()

    def paintEvent(self, event):
        self.draw()
        self.qp.begin(self)
        self.qp.end()

    def draw(self):
        randnum = random.randint(0, 255)
        rnd1 = random.randint(0, 255)
        rnd2 = random.randint(0, 255)
        rnd3 = random.randint(0, 255)
        self.qp.setBrush(QColor(rnd1, rnd2, rnd3))
        randnum = random.randint(0, 100)
        self.qp.drawEllipse(self.coords[0] - randnum, self.coords[1] - randnum,
                            self.coords[0] + randnum, self.coords[1] + randnum)
class Example(QWidget):
    def __init__(self):
        super().__init__()
        uic.loadUi('UI.ui', self)
        self.btn.clicked.connect(self.draw())
        self.qp = QPainter()

    def paint(self):
        self.qp.repaint()

    def paintEvent(self, event):
        self.draw()
        self.qp.begin(self)
        self.qp.end()

    def draw(self):
        self.qp.setBrush(QColor(245, 237, 20))
        randnum = random.randint(0, 100)
        self.qp.drawEllipse(self.coords[0] - randnum, self.coords[1] - randnum,
                            self.coords[0] + randnum, self.coords[1] + randnum)