Why the paintEvent is called repetitively in PySide6

In the below small piece of code why does the paintEvent method is called repetitively?

The print(f'paint {datetime.now()}') line confirms that the paintEvent method is called continuously.

#!/usr/bin/env python3.10

import sys
import random
from datetime import datetime

from PySide6.QtWidgets import (QApplication, QMainWindow, 
        QLabel, QWidget)
from PySide6.QtCore import (Qt, QRect, QPoint)
from PySide6.QtGui import (QColor, QPen, QBrush, QPainter,
        QPixmap)


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.label = QLabel()
        self.pixmap = QPixmap(500, 500)
        self.pixmap.fill(Qt.white)
        self.label.setPixmap(self.pixmap)
        self.setCentralWidget(self.label)

    
    def paintEvent(self, event):
        print(f'paint {datetime.now()}')
        self.pixmap = self.label.pixmap()

        painter = QPainter(self.pixmap)
        pen= QPen()
        pen.setWidth(3)
        painter.setPen(pen)
        painter.drawRect(100, 100, 300, 300)
        self.label.setPixmap(self.pixmap)

        painter.end()

if __name__ == "__main__":
    app = QApplication(sys.argv)

    mainWindow = MainWindow()
    mainWindow.show()

    app.exec()

How to prevent the paintEvent method unnecessary calls?

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum