ProgressBar in Kivy (automatically loading)

Viewed 18

I want a ProgressBar to start loading automatically when opening the application (similar to a loading screen). I have already created the bar. However, I've been trying to get the automatic loading process for two days. Does one of you have an idea? Thanks in advance!

py-file:

from kivy.uix.screenmanager import ScreenManager
from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.clock import Clock



#Window.size = (1366, 768)
#Window.fullscreen = True


class GATR(MDApp):


    def build(self):
        global sm 
        sm = ScreenManager()

        sm.add_widget(Builder.load_file("splash.kv"))
        sm.add_widget(Builder.load_file("login.kv"))

        return sm


    def on_start(self):
        Clock.schedule_once(self.login, 5)

        
    def login(*args):
        sm.current = "login"


        
if __name__=="__main__":
    GATR().run()

kv-file (The file with the progress bar):

MDScreen:
    name: "splash"
    MDFloatLayout:
        md_bg_color: 110/255, 123/255, 139/255, 1
        Image:
            source: "logo.png"
            size: 50, 50
            pos_hint: {"center_x":.5, "center_y":.6}

        MDLabel:
            text: "Text"
            text_color: 255, 255, 255, 0
            font_size: "60sp"
            pos_hint: {"center_x":.51, "center_y":.25}
            halign: "center"
            font_name: "3.ttf"
        
        ProgressBar:
            id: pb
            min: 0
            max: 100
            pos_hint: {"center_x": .5, "center_y": .1}
            size_hint_x: .8
1 Answers

I think something like this should do the work.

def foo(self):
    current = self.ids.pb.value #get current value of the progress bar
    if current >= 100: #check when it hits 100%, stop it
        return False
    current += 1 #increment current value
    self.ids.pb.value = current #update progress bar value
      
def on_start(self):
    Clock.schedule_interval(self.foo, 1/25) #kivy clock object to time it

It is just an idea, you should play around with it and implement it correctly with your codebase.

Related