Created
January 12, 2020 23:35
-
-
Save FloydanTheBeast/d8e110f4cf58054c23000dd93b28c501 to your computer and use it in GitHub Desktop.
Event handler override example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PyQt5.QtWidgets import QApplication, QWidget, QMessageBox, QLabel, QVBoxLayout | |
from PyQt5.QtCore import Qt | |
class UI(QWidget): | |
def __init__(self): | |
super().__init__() | |
layout = QVBoxLayout() | |
self.label = QLabel('x: _; y: _') | |
self.label.setStyleSheet('font-size: 48px; font-weight: 800') | |
layout.addWidget(self.label) | |
layout.setAlignment(Qt.AlignCenter) | |
self.setLayout(layout) | |
self.showFullScreen() | |
def mousePressEvent(self, e): | |
self.label.setText(f'x: {e.x()}; y: {e.y()}') | |
if __name__ == '__main__': | |
app = QApplication([]) | |
ui = UI() | |
app.exec_() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment