You can download this code by clicking the button below.
This code is now available for download.
This function creates a simple GUI application with a button. When the button is clicked, it prints out the position of the click.
Technology Stack : PyQt6
Code Type : Event handler
Code Difficulty : Intermediate
def random_button_click(event):
import sys
from PyQt6.QtWidgets import QApplication, QPushButton, QWidget, QVBoxLayout
app = QApplication(sys.argv)
window = QWidget()
layout = QVBoxLayout()
button = QPushButton('Click Me')
button.clicked.connect(lambda: print(f'Button was clicked at position {event.pos()}'))
layout.addWidget(button)
window.setLayout(layout)
window.show()
sys.exit(app.exec())