8000 Add QDialog example · realpython/materials@c46fd6a · GitHub
[go: up one dir, main page]

Skip to content

Commit c46fd6a

Browse files
committed
Add QDialog example
1 parent 2463976 commit c46fd6a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# filename: dialog.py
2+
3+
"""Dialog-Style application."""
4+
5+
import sys
6+
7+
from PyQt5.QtWidgets import QApplication
8+
from PyQt5.QtWidgets import QDialog
9+
from PyQt5.QtWidgets import QLineEdit
10+
from PyQt5.QtWidgets import QVBoxLayout
11+
from PyQt5.QtWidgets import QFormLayout
12+
from PyQt5.QtWidgets import QDialogButtonBox
13+
14+
15+
class Dialog(QDialog):
16+
"""Dialog."""
17+
18+
def __init__(self, parent=None):
19+
"""Initializer."""
20+
super().__init__(parent)
21+
self.setWindowTitle('QDialog')
22+
dlg_layout = QVBoxLayout()
23+
form_layout = QFormLayout()
24+
form_layout.addRow('Name:', QLineEdit())
25+
form_layout.addRow('Age:', QLineEdit())
26+
form_layout.addRow('Job:', QLineEdit())
27+
form_layout.addRow('Hobbies:', QLineEdit())
28+
dlg_layout.addLayout(form_layout)
29+
btns = QDialogButtonBox()
30+
btns.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Ok)
31+
dlg_layout.addWidget(btns)
32+
self.setLayout(dlg_layout)
33+
34+
35+
if __name__ == '__main__':
36+
app = QApplication(sys.argv)
37+
dlg = Dialog()
38+
dlg.show()
39+
sys.exit(app.exec_())

0 commit comments

Comments
 (0)
0