helpmepls
helpmepls

Reputation: 33

cannot display progress bar in window

I'm new to kivy so I don't really know how to display a progress bar in my NaviWindow. I cant seem to put progress bar inside the kv file so anyone knows how to display the bar in the NaviWindow?

.pyfile

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.progressbar import ProgressBar
from kivy.uix.screenmanager import ScreenManager, Screen

KV = """

WindowManager:
    NaviWindow:

<NaviWindow>:


"""

class WindowManager(ScreenManager):
    pass

class NaviWindow(Screen):
    def build(self):
        Progress = ProgressBar(max=1000)
        Progress.value = 100
        return Progress


class MyMainApp(App):
    def build(self):
        return Builder.load_string(KV)

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

Upvotes: 2

Views: 52

Answers (1)

eyllanesc
eyllanesc

Reputation: 243897

Only the App class (and obviously the classes that inherit from App) has the build method, but you seem to think that the Screen method also has it and is clearly incorrect. The solution is to add the ProgressBar using the add_widget() method:

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.progressbar import ProgressBar
from kivy.uix.screenmanager import ScreenManager, Screen

KV = """
WindowManager:
    NaviWindow:

<NaviWindow>:
"""


class WindowManager(ScreenManager):
    pass


class NaviWindow(Screen):
    def __init__(self, **kwargs):
        super(NaviWindow, self).__init__(**kwargs)
        self.progress = ProgressBar(max=1000)
        self.progress.value = 100
        self.add_widget(self.progress)


class MyMainApp(App):
    def build(self):
        return Builder.load_string(KV)


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

Upvotes: 3

Related Questions