-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalendar_widget.py
More file actions
89 lines (72 loc) · 2.64 KB
/
calendar_widget.py
File metadata and controls
89 lines (72 loc) · 2.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
import sys
from PyQt6.QtWidgets import (
QApplication,
QWidget,
QLabel,
QPushButton,
QVBoxLayout,
QCalendarWidget,
)
from PyQt6.QtCore import Qt, pyqtSlot, QDate
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, 500)
self.label_instruksi: QLabel = QLabel("klik tanggal di kalender dibawah", self)
self.label_instruksi.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.label_instruksi.setStyleSheet(
"""
font-size: 16px;
font-weight: bold;
margin: 10px;
"""
)
self.kalender: QCalendarWidget = QCalendarWidget(self)
self.kalender.setMinimumDate(QDate(2020, 1, 1))
self.kalender.setMaximumDate(QDate(2030, 12, 31))
self.kalender.setSelectedDate(QDate.currentDate())
self.kalender.setStyleSheet(
"""
QCalendarWidget QWidget {
alternate-background-color: #f0f0f0;
}
QCalendarWidget QAbstractItemView:enabled {
color: #2c3e50;
backgroun-color: white;
selection-background-color: #3498db;
selection-color: white;
}
"""
)
tanggal_sekarang: QDate = self.kalender.selectedDate()
teks_tanggal: str = tanggal_sekarang.toString("dddd, dd MMMM yyyy")
self.label_hasil: QLabel = QLabel(
f"tanggal dipilih adalah:\n{teks_tanggal}", self
)
self.label_hasil.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.label_hasil.setStyleSheet(
"""
font-size: 18px;
padding: 20px;
backgroun-color: #d5f5e3;
border-radius: 10px;
margin: 10xp;
"""
)
self.kalender.clicked.connect(self.saat_tanggal_dipilih)
self.layout_utama: QVBoxLayout = QVBoxLayout()
self.layout_utama.addWidget(self.label_instruksi)
self.layout_utama.addWidget(self.kalender)
self.layout_utama.addWidget(self.label_hasil)
self.setLayout(self.layout_utama)
def saat_tanggal_dipilih(self, tanggal: QDate) -> None:
teks_format: str = tanggal.toString("dddd, dd MMMM yyyy")
self.label_hasil.setText(f"tanggal dipilih adalah:\n{teks_format}")
if __name__ == "__main__":
aplikasi: QApplication = QApplication(sys.argv)
jendela: AplikasiKita = AplikasiKita()
jendela.show()
sys.exit(aplikasi.exec())