signals_and_slots_1b.py 695 B

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