-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.py
50 lines (38 loc) · 1.4 KB
/
gui.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
import sys
import random
from PySide2.QtWidgets import (QApplication, QLabel, QPushButton,
QVBoxLayout, QWidget, QGroupBox, QHBoxLayout)
from PySide2.QtCore import Slot, Qt
class MyWidget(QWidget):
def __init__(self):
QWidget.__init__(self)
self.hello = ["Hello Bla", "123", "blabla",
"Hola Mundo", "zzzzzz"]
self.horizontalGroupBox = QGroupBox("Horizontal layout")
self.button1 = QPushButton("Click me!")
self.button2 = QPushButton("Click me!")
self.text = QLabel("Hello World")
self.text.setAlignment(Qt.AlignCenter)
self.gblayout = QHBoxLayout();
self.gblayout.addWidget(self.button1)
self.gblayout.addWidget(self.button2)
self.horizontalGroupBox.setLayout(self.gblayout)
self.layout = QVBoxLayout()
self.layout.addWidget(self.text)
self.layout.addWidget(self.horizontalGroupBox)
self.setLayout(self.layout)
# Connecting the signal
self.button1.clicked.connect(self.magic1)
self.button2.clicked.connect(self.magic2)
@Slot()
def magic1(self):
self.text.setText(random.choice(self.hello))
@Slot()
def magic2(self):
self.text.setText("DEFAULT")
if __name__ == "__main__":
app = QApplication(sys.argv)
widget = MyWidget()
widget.resize(800, 600)
widget.show()
sys.exit(app.exec_())