[Python] Kivy: Using progress bar to simulate a process and then execute other code

Discussão em 'Python' iniciado por Stack, Novembro 28, 2024.

  1. Stack

    Stack Membro Participativo

    I'm trying to use the progress bar in Kivy to simulate completion of an external process, at the end of which a function should run to provide some results.

    I've looked at all the posts here discussing progress bar and Clock scheduled events. I've tried the methods, but I still can't get the effect I want.

    Within my main widget class, I have the following methods defined:

    def update_progbar(self):
    print(self.progbar.value)
    self.progbar.value += 10.0


    def start_progbar_update(self):
    print("start progbar update")
    self.update_progbar_event = Clock.schedule_interval(lambda dt: self.update_progbar(),1)


    def stop_progbar_update(self):
    print("stop progbar update")
    self.update_progbar_event.cancel()


    def run_program(self):
    if self.progbar.value < 100.0:
    self.start_progbar_update()
    elif self.progbar.value >= 100.0:
    self.stop_progbar_update()

    #wait for progress bar to fill up, then execute code below
    results = some_function(args)


    So, the effect is to display to the user a simulated process that takes some time, and then produces some results.

    The starting of progress bar update is working. I see the progress bar widget fill up 10% every second. But after it gets to 100%, it keeps running and keeps printing "100.0" and never exits.

    I can't seem to get the condition if progbar.value >= 100.0: stop_progbar_update() to work. The Clock schedule interval event never gets cancelled.

    The code below it never gets a chance to run.

    Continue reading...

Compartilhe esta Página