1. 코드

import sys

from PyQt5.QtWidgets import QApplication, QWidget 
from PyQt5.QtGui import QPainter, QColor, QFont, QPen
from PyQt5.QtCore import Qt
import random

class 점넣기(QWidget):

    def __init__(self):
        super().__init__()
        self.UI초기화()

    def UI초기화(self):
        self.setGeometry(300, 300, 500, 500)
        self.setWindowTitle('QPainter!')
        self.show()

    def paintEvent(self, event):
        paint = QPainter()
        paint.begin(self)
        self.drawRandomPoint(paint)
        paint.end()

    def drawRandomPoint(self, paint):
        pen = QPen()
        colors = [Qt.red, Qt.blue, Qt.green]
        size = self.size()
        print(f'높이와 넓이 : {size.height()}, {size.width()}')

        for _ in range(1000):
            pen.setColor(QColor(random.choice(colors)))
            pen.setWidth(random.randint(1, 20))
            paint.setPen(pen)

            x = random.randint(1, size.width() - 1)
            y = random.randint(1, size.height() - 1)

            paint.drawPoint(x, y)

프로그램무한반복 = QApplication(sys.argv)
실행인스턴스 = 점넣기()
프로그램무한반복.exec_()

2. 상세 내용

점도 결국에는 팬으로 그리게 됩니다. PyQt에서 점은 넓이와 높이가 있는 선입니다.

HTML Color Codes

QColor - Qt for Python

QFont - Qt for Python

QPen - Qt for Python

3. 실행 화면

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/26d83e4d-ef52-408a-978a-b84c747974c7/Untitled.png