signals_and_slots_1.py 529 B

123456789101112131415161718192021222324252627
  1. import sys
  2. from PyQt5.QtWidgets import QMainWindow, QPushButton, QApplication
  3. def the_button_was_clicked():
  4. print("Button was clicked")
  5. class MainWindow(QMainWindow):
  6. def __init__(self):
  7. super().__init__()
  8. self.setWindowTitle("My App")
  9. button = QPushButton("Press Me!")
  10. button.clicked.connect(the_button_was_clicked)
  11. # Set the central widget of the window
  12. self.setCentralWidget(button)
  13. app = QApplication(sys.argv)
  14. window = MainWindow()
  15. window.show()
  16. app.exec_()