-
Notifications
You must be signed in to change notification settings - Fork 6
/
21_vbox_layout.py
executable file
·79 lines (62 loc) · 2.16 KB
/
21_vbox_layout.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
#
# (C) Copyright 2017, 2018 Pavel Tisnovsky
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Pavel Tisnovsky
#
# tento import je zapotřebí kvůli nutnosti zpracování parametrů
# předávaných přes příkazový řádek
import sys
# import "jádra" frameworku Qt i modulu pro GUI
from PySide import QtCore, QtGui
# nový widget bude odvozen od obecného widgetu
class MainWindow(QtGui.QWidget):
def __init__(self):
# zavoláme konstruktor předka
super(MainWindow, self).__init__()
# konfigurace GUI + přidání widgetu do okna
self.prepareGUI()
def prepareGUI(self):
# velikost není potřeba specifikovat
# self.resize(320, 240)
self.setWindowTitle("Quit Button")
# tlačítka
button1 = QtGui.QPushButton("One")
button2 = QtGui.QPushButton("Two")
button3 = QtGui.QPushButton("Three")
button4 = QtGui.QPushButton("Four")
button5 = QtGui.QPushButton("Five")
# vytvoření správce geometrie a umístění widgetů
layout = QtGui.QVBoxLayout()
layout.addWidget(button1)
layout.addWidget(button2)
layout.addWidget(button3)
layout.addWidget(button4)
layout.addWidget(button5)
# nastavení správce geometrie a vložení všech komponent do okna
self.setLayout(layout)
# navázání akce na signál
button1.clicked.connect(self.quit)
button2.clicked.connect(self.quit)
button3.clicked.connect(self.quit)
button4.clicked.connect(self.quit)
button5.clicked.connect(self.quit)
def run(self, app):
# zobrazení okna na obrazovce
self.show()
# vstup do smyčky událostí (event loop)
app.exec_()
def quit(self):
print("Closing...")
self.close()
def main():
app = QtGui.QApplication(sys.argv)
MainWindow().run(app)
if __name__ == "__main__":
main()