-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage_box.py
More file actions
103 lines (84 loc) · 3.64 KB
/
message_box.py
File metadata and controls
103 lines (84 loc) · 3.64 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
97
98
99
100
101
102
103
import sys
from PyQt6.QtGui import QPagedPaintDevice
from PyQt6.QtWidgets import (
QApplication,
QWidget,
QLabel,
QPushButton,
QVBoxLayout,
QMessageBox,
)
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 aplikasi kita")
self.setGeometry(300, 300, 400, 300)
self.tombol_info: QPushButton = QPushButton("tampilkan info pesan", self)
self.tombol_info.clicked.connect(self.tampilkan_pesan_info)
self.tombol_peringatan: QPushButton = QPushButton(
"tampilkan info warning", self
)
self.tombol_peringatan.clicked.connect(self.tampilkan_pesan_peringatan)
self.tombol_critical: QPushButton = QPushButton("tampilkan info critical", self)
self.tombol_critical.clicked.connect(self.tampilkan_pesan_critical)
self.tombol_tanya: QPushButton = QPushButton("tampilkan info pertanyaan", self)
self.tombol_tanya.clicked.connect(self.tampilkan_pesan_tanya)
self.layout_utama: QVBoxLayout = QVBoxLayout()
self.layout_utama.addWidget(self.tombol_info)
self.layout_utama.addWidget(self.tombol_peringatan)
self.layout_utama.addWidget(self.tombol_critical)
self.layout_utama.addWidget(self.tombol_tanya)
self.layout_utama.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.setLayout(self.layout_utama)
@pyqtSlot()
def tampilkan_pesan_info(self) -> None:
kotak_pesan: QMessageBox = QMessageBox()
kotak_pesan.setIcon(QMessageBox.Icon.Information)
kotak_pesan.setWindowTitle("informasi pesan")
kotak_pesan.setText("ini adalah contoh dari pesan informasi")
kotak_pesan.setStandardButtons(QMessageBox.StandardButton.Ok)
kotak_pesan.exec()
@pyqtSlot()
def tampilkan_pesan_peringatan(self) -> None:
kotak_pesan: QMessageBox = QMessageBox()
kotak_pesan.setIcon(QMessageBox.Icon.Warning)
kotak_pesan.setWindowTitle("warning pesan")
kotak_pesan.setText("ini adalah contoh dari pesan warning")
kotak_pesan.setStandardButtons(
QMessageBox.StandardButton.Ok | QMessageBox.StandardButton.Cancel
)
hasil = kotak_pesan.exec()
if hasil == QMessageBox.StandardButton.Ok:
print("si user menenekan tombol OK")
else:
print("si user menekan tombol cancel atau menutup dari jendela")
@pyqtSlot()
def tampilkan_pesan_critical(self) -> None:
kotak_pesan: QMessageBox = QMessageBox()
kotak_pesan.setIcon(QMessageBox.Icon.Critical)
kotak_pesan.setWindowTitle("error pesan")
kotak_pesan.setText("ini adalah contoh dari pesan error")
kotak_pesan.setDetailedText("file ini mengandung virus 12345 dari spu slowy")
kotak_pesan.setStandardButtons(QMessageBox.StandardButton.Abort)
kotak_pesan.exec()
@pyqtSlot()
def tampilkan_pesan_tanya(self) -> None:
jawaban = QMessageBox.question(
self,
"konfirmasi",
"apakah indonesia adalah negara demokrasi?",
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
QMessageBox.StandardButton.No,
)
if jawaban == QMessageBox.StandardButton.Yes:
print("si user mengatakan iya")
else:
print("si user mengatakan tidak")
if __name__ == "__main__":
aplikasi: QApplication = QApplication(sys.argv)
jendela: AplikasiKita = AplikasiKita()
jendela.show()
sys.exit(aplikasi.exec())