You can download this code by clicking the button below.
This code is now available for download.
Create a simple GUI window with a button. When the button is clicked, a message will be printed to the console.
Technology Stack : PyQt6
Code Type : PyQt6 GUI
Code Difficulty : Intermediate
def random_button_click():
import sys
from PyQt6.QtWidgets import QApplication, QPushButton, QWidget
from PyQt6.QtCore import Qt
app = QApplication(sys.argv)
window = QWidget()
window.setWindowTitle("Random Button Click")
button = QPushButton("Click Me", window)
button.setGeometry(50, 50, 100, 50)
button.clicked.connect(lambda: print("Button was clicked!"))
window.show()
sys.exit(app.exec())