-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogress_bar.py
More file actions
82 lines (64 loc) · 2.48 KB
/
progress_bar.py
File metadata and controls
82 lines (64 loc) · 2.48 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
import sys
from PyQt6.QtWidgets import (
QApplication,
QWidget,
QLabel,
QPushButton,
QVBoxLayout,
QProgressBar,
)
from PyQt6.QtCore import Qt, pyqtSlot, QTimer
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, 400, 250)
self.label_instruksi: QLabel = QLabel("klik tombol untuk mulai", self)
self.label_instruksi.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.bilah_progress: QProgressBar = QProgressBar(self)
self.bilah_progress.setRange(0, 100)
self.bilah_progress.setValue(0)
self.bilah_progress.setTextVisible(True)
# self.bilah_progress.setStyleSheet(
# """
# QProgressBar::chunk {
# background-color: #27ae60;
# border-radius: 8px;
# }
# """
# )
self.nilai_saat_ini: int = 0
self.tombol_mulai: QPushButton = QPushButton("mulai proses bar", self)
self.tombol_mulai.clicked.connect(self.mulai_proses)
self.timer_proses: QTimer = QTimer(self)
self.timer_proses.timeout.connect(self.update_progress)
self.layout_utama: QVBoxLayout = QVBoxLayout()
self.layout_utama.addWidget(self.label_instruksi)
self.layout_utama.addWidget(self.bilah_progress)
self.layout_utama.addWidget(self.tombol_mulai)
self.layout_utama.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.setLayout(self.layout_utama)
def mulai_proses(self) -> None:
if not self.timer_proses.isActive():
self.nilai_saat_ini = 0
self.bilah_progress.setValue(0)
self.tombol_mulai.setText("berhenti")
self.timer_proses.start(100)
else:
self.hentikan_proses()
def hentikan_proses(self) -> None:
self.timer_proses.stop()
self.tombol_mulai.setText("mulai dari proses")
def update_progress(self) -> None:
self.nilai_saat_ini += 1
self.bilah_progress.setValue(self.nilai_saat_ini)
if self.nilai_saat_ini >= 100:
self.timer_proses.stop()
self.tombol_mulai.setText("klik untuk ngulang")
if __name__ == "__main__":
aplikasi: QApplication = QApplication(sys.argv)
jendela: AplikasiKita = AplikasiKita()
jendela.show()
sys.exit(aplikasi.exec())