signals_and_slots_2.py 669 B

123456789101112131415161718192021222324252627282930
  1. import sys
  2. from PyQt5.QtWidgets import QMainWindow, QPushButton, QApplication
  3. class MainWindow(QMainWindow):
  4. def __init__(self):
  5. super().__init__()
  6. self.setWindowTitle("My App")
  7. self.button = QPushButton("Press Me!")
  8. self.button.clicked.connect(self.the_button_was_clicked)
  9. # Set the central widget of the window
  10. self.setCentralWidget(self.button)
  11. def the_button_was_clicked(self):
  12. self.button.setText("You already clicked me.")
  13. self.button.setEnabled(False)
  14. self.setWindowTitle("A new window title")
  15. app = QApplication(sys.argv)
  16. window = MainWindow()
  17. window.show()
  18. app.exec_()