-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput_text.py
More file actions
96 lines (82 loc) · 2.78 KB
/
input_text.py
File metadata and controls
96 lines (82 loc) · 2.78 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
89
90
91
92
93
94
95
96
import sys
from PyQt6.QtWidgets import (
QApplication,
QWidget,
QLabel,
QLineEdit,
QPushButton,
QVBoxLayout,
)
from PyQt6.QtCore import Qt, pyqtSlot
class AplikasiKita(QWidget):
def __init__(self) -> None:
super().__init__()
self.inisialisasi_interface()
def inisialisasi_interface(self) -> None:
self.setWindowTitle("program kita")
self.setGeometry(300, 300, 400, 250)
self.label_instruksi: QLabel = QLabel("masukkan nama kamu: ", self)
self.label_instruksi.setAlignment(Qt.AlignmentFlag.AlignLeft)
self.input_teks: QLineEdit = QLineEdit(self)
self.input_teks.setPlaceholderText("masukkan nama kamu disni ... :)")
self.input_teks.setStyleSheet(
"""
font-size: 16px;
padding: 8px;
border: 2px solid #bdc3c7;
border-radius: 8px;
"""
)
self.tombol_proses: QPushButton = QPushButton("proses", self)
self.tombol_proses.setStyleSheet(
"""
font-weight: bold;
padding: 10px;
"""
)
self.tombol_proses.clicked.connect(self.saat_tombol_ditekan)
self.label_hasil: QLabel = QLabel("nama kamu disini...", self)
self.label_hasil.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.label_hasil.setStyleSheet(
"""
font-size: 18px;
padding: 15px;
margin-top: 10px;
"""
)
self.layout_utama: QVBoxLayout = QVBoxLayout()
self.layout_utama.addWidget(self.label_instruksi)
self.layout_utama.addWidget(self.input_teks)
self.layout_utama.addWidget(self.tombol_proses)
self.layout_utama.addWidget(self.label_hasil)
self.setLayout(self.layout_utama)
@pyqtSlot()
def saat_tombol_ditekan(self) -> None:
teks_dari_input: str = self.input_teks.text().strip()
if teks_dari_input == "":
self.label_hasil.setText("kamu tidak ketik apa-apa")
self.label_hasil.setStyleSheet(
"""
font-size: 18px;
color: #e74c3c;
font-weight: bold;
padding: 15px;
margin-top: 10px;
"""
)
else:
self.label_hasil.setText(f"wello {teks_dari_input}, apa kabar?")
self.label_hasil.setStyleSheet(
"""
font-size: 18px;
color: #27ae60;
font-weight: bold;
padding: 15px;
margin-top: 10px;
"""
)
if __name__ == "__main__":
aplikasi: QApplication = QApplication(sys.argv)
jendela: AplikasiKita = AplikasiKita()
jendela.show()
sys.exit(aplikasi.exec())