-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput_dialog.py
More file actions
70 lines (57 loc) · 2.15 KB
/
input_dialog.py
File metadata and controls
70 lines (57 loc) · 2.15 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
import sys
from PyQt6.QtWidgets import QApplication, QInputDialog, QWidget, QLabel, 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("contoh dari aplikasi kita")
self.setGeometry(300, 300, 450, 350)
self.label_hasil: QLabel = QLabel("hasil dari input QInputDialog", self)
self.label_hasil.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.label_hasil.setStyleSheet(
"""
font-size: 18px;
padding: 20px;
margin: 10px;
"""
)
self.tombol_input_teks: QPushButton = QPushButton("masukkan nama", self)
self.tombol_input_teks.clicked.connect(self.minta_input_teks)
self.layout_utama: QVBoxLayout = QVBoxLayout()
self.layout_utama.addWidget(self.label_hasil)
self.layout_utama.addWidget(self.tombol_input_teks)
self.layout_utama.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.setLayout(self.layout_utama)
@pyqtSlot()
def minta_input_teks(self) -> None:
teks_yang_dimasukkan, diterima = QInputDialog.getText(
self,
"masukkan nama",
"nama lengkap kamu:",
text="contohnya: arfy slowy"
)
if diterima and teks_yang_dimasukkan.strip() != "":
self.label_hasil.setText(f"wello {teks_yang_dimasukkan}")
self.label_hasil.setStyleSheet(
"""
font-size: 16px;
margin: 10px;
padding: 20px;
"""
)
elif diterima:
self.label_hasil.setText("nama tidak boleh kosong")
self.label_hasil.setStyleSheet(
"""
font-size: 16px;
padding: 20px;
margin: 10px;
"""
)
if __name__ == "__main__":
aplikasi: QApplication = QApplication(sys.argv)
jendela: AplikasiKita = AplikasiKita()
jendela.show()
sys.exit(aplikasi.exec())