| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- import sys
- from random import choice
- from PyQt5.QtWidgets import QMainWindow, QPushButton, QApplication
- window_titles = [
- "My App",
- "My App",
- "Still My App",
- "Still My App",
- "What on earth",
- "What on earth",
- "This is surprising",
- "This is surprising",
- "Something went wrong"
- ]
- class MainWindow(QMainWindow):
- def __init__(self):
- super().__init__()
- self.n_times_clicked = 0
- self.setWindowTitle("My App")
- self.button = QPushButton("Press Me!")
- self.button.clicked.connect(self.the_button_was_clicked)
- self.windowTitleChanged.connect(self.the_window_tile_changed)
- # Set the central widget of the window
- self.setCentralWidget(self.button)
- def the_button_was_clicked(self):
- print("Clicked.")
- new_window_tile = choice(window_titles)
- print("Setting title: %s" % new_window_tile)
- self.setWindowTitle(new_window_tile)
- def the_window_tile_changed(self, window_tile):
- print("Window title changed: %s" % window_tile)
- if window_tile == "Something went wrong":
- self.button.setDisabled(True)
- app = QApplication(sys.argv)
- window = MainWindow()
- window.show()
- app.exec_()
|