Skip to content Skip to sidebar Skip to footer

Open Kivy Popup Before Continuing

My kivy popup does not appear on the screen until the rest of the code in my method finishes running. I am trying to display a progress bar so it is worthless in it's current state

Solution 1:

This is based on member 'inclement's' answer. I am not 100% what you are attempting to do but here is some code I tested that kicks off a long-running task in its own thread and holds the popup open until that task completes.

Kivy .kv file entry

Button:text:"do..."on_release:app.root.info_popup(self)# your app may need root.info_popup(self)

In the app, the target method

definfo_popup(self, _button: Button):
    print(str(type(_button)))
    popup_content = ProgressBar(max=10)

    popup = Popup(title="Countdown",
                  size_hint=(None, None), size=(400, 180),
                  content=popup_content,
                  auto_dismiss=False)
    print("starting a new thread to do the countdown")
    threading.Thread(target=partial(self.update_progress, an_object=popup_content,
                                    the_popup=popup), daemon=True).start()
    popup.open()

which starts this function as its own thread

def update_progress(self, an_object, the_popup: Popup):
    for i in range(10, -1, -1):
        time.sleep(1.0)
        print("progress: {}".format(i))
        an_object.value = i
    the_popup.dismiss()
    print("I have dismissed the popup")

Solution 2:

I solved the issue by using the Clock.schedule_once() function to schedule my other threaded updates.

Post a Comment for "Open Kivy Popup Before Continuing"