Ticket #6425: windows.py

File windows.py, 925 bytes (added by Zach Pearson, 4 years ago)
Line 
1from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton, QLabel, QVBoxLayout, QWidget
2from PyQt6.QtWidgets import QDialogButtonBox as qbbox
3import sys
4
5
6class AnotherWindow(QWidget):
7 """
8 This "window" is a QWidget. If it has no parent, it
9 will appear as a free-floating window as we want.
10 """
11 def __init__(self):
12 super().__init__()
13 layout = QVBoxLayout()
14 self.label = qbbox(qbbox.StandardButton.Ok)
15 layout.addWidget(self.label)
16 self.setLayout(layout)
17
18
19class MainWindow(QMainWindow):
20
21 def __init__(self):
22 super().__init__()
23 self.button = QPushButton("Push for Window")
24 self.button.clicked.connect(self.show_new_window)
25 self.setCentralWidget(self.button)
26
27 def show_new_window(self, checked):
28 self.w = AnotherWindow()
29 self.w.show()
30
31
32app = QApplication(sys.argv)
33w = MainWindow()
34w.show()
35app.exec()