TomSchimansky / CustomTkinter

A modern and customizable python UI-library based on Tkinter
MIT License
11.62k stars 1.09k forks source link

ProgressBar determinate_speed divided by 50 #2606

Open erukami opened 1 month ago

erukami commented 1 month ago

In the step method of ctk_progessbar.py, the determinate_speed attribute is being divided by 50. I may have missed it in the documentation, but I did not see a purpose for this.

def step(self):
    """ increase progress """
    if self._mode == "determinate":
        self._determinate_value += self._determinate_speed / 50
        if self._determinate_value > 1:
            self._determinate_value -= 1
        self._draw()
    else:
        self._indeterminate_value += self._indeterminate_speed
        self._draw()

This presents an issue if manually using the step method and configuring the determinate_speed based on an incrementer:

import customtkinter

app = customtkinter.CTk()
progress = customtkinter.CTkProgressBar(app, mode="determinate", determinate_speed=.25)
progress.set(0)

print("Determinate speed is .25")
for i in range(1,5):
    progress.step()
    speed = progress.get()
    print(f"Incremented to {speed} instead of {speed * 50}")

Result:

Determinate speed is .25
Incremented to 0.005 instead of 0.25
Incremented to 0.01 instead of 0.5
Incremented to 0.015 instead of 0.75
Incremented to 0.02 instead of 1.0

Maybe it is a carryover from the _internal_loop method and not intentional?

def _internal_loop(self):
   if self._loop_running:
        if self._mode == "determinate":
            self._determinate_value += self._determinate_speed / 50
            if self._determinate_value > 1:
                self._determinate_value -= 1
            self._draw()
            self._loop_after_id = self.after(20, self._internal_loop)
        else:
            self._indeterminate_value += self._indeterminate_speed
            self._draw()
            self._loop_after_id = self.after(20, self._internal_loop)
DenishKakadiya commented 1 month ago

Because of dividing by 50, step increament in each step is also double of what determinate_speed is set.