我是新手,所以我真的不知道如何在NaviWindow中显示进度条。我似乎无法将进度条放在kv文件中,所以谁知道如何在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()
答案 0 :(得分:3)
只有App类(显然是从App继承的类)具有build方法,但是您似乎认为Screen方法也具有build方法,并且显然是错误的。解决方案是使用add_widget()
方法添加ProgressBar:
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()