| 1 | from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton, QLabel, QVBoxLayout, QWidget
|
|---|
| 2 | from PyQt6.QtWidgets import QDialogButtonBox as qbbox
|
|---|
| 3 | import sys
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 | class 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 |
|
|---|
| 19 | class 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 |
|
|---|
| 32 | app = QApplication(sys.argv)
|
|---|
| 33 | w = MainWindow()
|
|---|
| 34 | w.show()
|
|---|
| 35 | app.exec()
|
|---|