fixed progressbar start stop speed increase #775

This commit is contained in:
Tom Schimansky 2022-12-06 11:27:35 +01:00
parent 2c7b2c5030
commit dd223a15b5
2 changed files with 8 additions and 11 deletions

View File

@ -58,6 +58,7 @@ class CTkProgressBar(CTkBaseClass):
self._variable = variable
self._variable_callback_blocked = False
self._variable_callback_name = None
self._loop_after_id = None
# shape
self._corner_radius = ThemeManager.theme["CTkProgressBar"]["corner_radius"] if corner_radius is None else corner_radius
@ -249,13 +250,15 @@ class CTkProgressBar(CTkBaseClass):
return self._determinate_value
def start(self):
""" start indeterminate mode """
""" start automatic mode """
if not self._loop_running:
self._loop_running = True
self._internal_loop()
def stop(self):
""" stop indeterminate mode """
""" stop automatic mode """
if self._loop_after_id is not None:
self.after_cancel(self._loop_after_id)
self._loop_running = False
def _internal_loop(self):
@ -265,13 +268,14 @@ class CTkProgressBar(CTkBaseClass):
if self._determinate_value > 1:
self._determinate_value -= 1
self._draw()
self.after(20, self._internal_loop)
self._loop_after_id = self.after(20, self._internal_loop)
else:
self._indeterminate_value += self._indeterminate_speed
self._draw()
self.after(20, self._internal_loop)
self._loop_after_id = self.after(20, self._internal_loop)
def step(self):
""" increase progress """
if self._mode == "determinate":
self._determinate_value += self._determinate_speed / 50
if self._determinate_value > 1:

View File

@ -70,11 +70,4 @@ tabview_1.pack(pady=10, padx=10)
tabview_1.add("CTkTabview")
tabview_1.add("Tab 2")
progressbar_1.configure(mode="indeterminate")
progressbar_1.start()
#progressbar_1.stop()
#progressbar_1.start()
#progressbar_1.stop()
#progressbar_1.start()
app.mainloop()