1. 코드

from PyQt5.QtWidgets import QWidget, QApplication, QLabel, QVBoxLayout
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QFont
import sys

class 이벤트함수(QWidget):

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

    def UI초기화(self):
        x = 0
        y = 0

        self.location = f"x좌표는 : {x}, y좌표는 : {y}" 
        self.label1 = QLabel(self.location, self)
        self.label1.setFont(QFont("Decorative",20))
        self.label2 = QLabel("마우스를 클릭 또는 더블클릭 해보세요")

        self.setMouseTracking(True) 

        self.vbox = QVBoxLayout()
        self.vbox.addWidget(self.label1, alignment=Qt.AlignCenter)
        self.vbox.addWidget(self.label2, alignment=Qt.AlignCenter)

        self.setLayout(self.vbox)
        self.setWindowTitle('Reimplementing Event Handler2')
        self.setGeometry(300, 300, 400, 300)
        self.show()

   
    def mousePressEvent(self, event):
        self.label2.setText('마우스를 클릭했습니다.')

    def mouseDoubleClickEvent(self, event):
        self.label2.setText('마우스를 더블클릭했습니다.')

    def mouseMoveEvent(self, event):
        x = event.x()
        y = event.y()

        location = 'x좌표는 : {0}, y좌표는 : {1}'.format(x, y) 

        self.label1.setText(location)

프로그램무한반복 = QApplication(sys.argv)
실행인스턴스 = 이벤트함수()
프로그램무한반복.exec_()

2. 상세 내용

x = 0
y = 0

self.location = f"x좌표는 : {x}, y좌표는 : {y}"
self.label1 = QLabel(self.location, self)
self.label1.setFont(QFont("Decorative", 20))
self.label2 = QLabel("마우스를 클릭 또는 더블클릭 해보세요")

self.setMouseTracking(True)
def mousePressEvent(self, event):
    self.label2.setText('마우스를 클릭했습니다.')
def mouseDoubleClickEvent(self, event):
    self.label2.setText('마우스를 더블클릭했습니다.')
def mouseMoveEvent(self, event):
    x = event.x()
    y = event.y()

    location = 'x좌표는 : {0}, y좌표는 : {1}'.format(x, y)

    self.label1.setText(location)

3. 실행 화면

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/d8707739-76a6-4985-9ea6-46d5b6af0e34/Untitled.png