As an option:
import sys from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PyQt5.QtGui import * class Instruction: def paint(self, painter): raise NotImplementedError() class LineInstruction(Instruction): def __init__(self, e): self._e = e def paint(self, painter): painter.setBrush(QColor(50, 200, 50, 255)) painter.drawRect(self._e) class ContextTest: instructions = [] class ExampleDraw(QWidget): def __init__(self): super().__init__() def mousePressEvent(self, event): e = QRect(event.pos().x(), event.pos().y(), 50, 50) instruction = LineInstruction(e) ContextTest.instructions.append(instruction) self.update() def paintEvent(self, QPaintEvent): super().paintEvent(QPaintEvent) qp = QPainter(self) for instruction in ContextTest.instructions: instruction.paint(qp) if __name__ == '__main__': app = QApplication(sys.argv) w = ExampleDraw() w.show() sys.exit(app.exec_())

Option SECOND:
import sys from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PyQt5.QtGui import * class MainGui(QWidget): def __init__(self): super().__init__() self.resize(600, 400) self.init_UI() def init_UI(self): self.pixmap = QPixmap(600, 400) self.pixmap.fill(QColor(239, 239, 239, 180)) self.label = QLabel(self) self.label.setPixmap(self.pixmap) self.label.mousePressEvent = self.get_pos def drawPoints(self, pos): pen = QPen(QColor(50, 200, 50, 170), 50) qp = QPainter() qp.begin(self.label.pixmap()) qp.setPen(pen) qp.drawPoint(pos.x(), pos.y()) self.label.update() def get_pos(self, event): X = event.pos().x() y = event.pos().y() self.drawPoints(event.pos()) if __name__ == '__main__': app = QApplication(sys.argv) ex = MainGui() ex.show() sys.exit(app.exec_())
