-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHello_world_Stacked Test.py
More file actions
88 lines (61 loc) · 2.28 KB
/
Hello_world_Stacked Test.py
File metadata and controls
88 lines (61 loc) · 2.28 KB
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
80
81
82
83
84
85
86
87
88
#Aaron Parker
#170614
#Event Driven Programming
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Hello World")
self.stacked_layout = QStackedLayout()
self.stacked_widget = QWidget()
self.stacked_widget.setLayout(self.stacked_layout)
self.setCentralWidget(self.stacked_widget)
self.create_main_layout()
self.create_hello_layout()
self.stacked_layout.setCurrentIndex(0) #sets the layout that will show first
def create_main_layout(self):
#widgets
self.text_box = QLineEdit()
self.submit_button = QPushButton("Submit")
#layout
self.layout = QVBoxLayout()
#widgets
self.layout.addWidget(self.text_box)
self.layout.addWidget(self.submit_button)
#Widget to hold layout
self.widget = QWidget()
#add layout to widget
self.widget.setLayout(self.layout)
#set central widget
self.stacked_layout.addWidget(self.widget)
self.submit_button.clicked.connect(self.switch_layout)
def switch_layout(self):
index = self.stacked_layout.currentIndex()
if index == 0:
self.stacked_layout.setCurrentIndex(1)
elif index == 1:
self.stacked_layout.setCurrentIndex(0)
index = self.stacked_layout.currentIndex()
if index == 0:
self.text_box.clear()
elif index == 1:
name = self.text_box.text()
self.label.setText("Hello {0}.".format(name))
def create_hello_layout(self):
self.label = QLabel()
self.back_button = QPushButton("Back")
self.hello_layout = QVBoxLayout()
self.hello_layout.addWidget(self.label)
self.hello_layout.addWidget(self.back_button)
self.hello_widget = QWidget()
self.hello_widget.setLayout(self.hello_layout)
self.stacked_layout.addWidget(self.hello_widget)
self.back_button.clicked.connect(self.switch_layout)
if __name__ == "__main__":
application = QApplication(sys.argv)
window = MainWindow()
window.show()
window.raise_()
application.exec_()