-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlabel_button.py
More file actions
66 lines (55 loc) · 1.77 KB
/
label_button.py
File metadata and controls
66 lines (55 loc) · 1.77 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
import sys
from PyQt6.QtWidgets import QApplication, QWidget, QLabel, QPushButton, QVBoxLayout
from PyQt6.QtCore import Qt, pyqtSlot
from random import choice
class AplikasiKita(QWidget):
def __init__(self) -> None:
super().__init__()
self.inisialisasi_interface()
def inisialisasi_interface(self) -> None:
self.setGeometry(300, 300, 400, 250)
self.label_utama: QLabel = QLabel("", self)
self.label_utama.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.label_utama.setStyleSheet(
"""
font-size: 18px;
font-weight: bold;
color: #2c3e50;
padding: 20px;
"""
)
self.tombol_aksi: QPushButton = QPushButton("klik untuk ganti si label", self)
self.tombol_aksi.setStyleSheet(
"""
font-size: 16px;
background-color: #3498db;
border-radius: 8px;
"""
)
self.tombol_aksi.clicked.connect(self.saat_tombol_ditekan)
self.layout_utama: QVBoxLayout = QVBoxLayout()
self.layout_utama.addWidget(self.label_utama)
self.layout_utama.addWidget(self.tombol_aksi)
self.setLayout(self.layout_utama)
@pyqtSlot()
def saat_tombol_ditekan(self) -> None:
nama: list[str] = [
"amba",
"arief",
"arfy",
"nongpal",
"mamad",
"mochie",
"vinz",
"mas rusdi",
"mas gatot penjas",
"xaviera",
"sandhika galih",
]
self.label_utama.setText(choice(nama))
print("label diganti!")
if __name__ == "__main__":
aplikasi: QApplication = QApplication(sys.argv)
jendela: AplikasiKita = AplikasiKita()
jendela.show()
sys.exit(aplikasi.exec())