【发布时间】:2019-11-13 22:42:19
【问题描述】:
我正在使用 Kivy 和 KivyMD,我正在尝试实现 MDToolbar。运行我的程序后,我收到此错误:AttributeError: 'NoneType' object has no attribute 'theme_cls'。我只包含了我的程序中的相关代码。在添加 MDToolbar 之前,一切都运行良好。我怎样才能让 MDToolbar 工作?请帮忙!
我的完整错误:
Parser: File "<inline>", line 22:
...
20:<MDToolbar>
21: size_hint_y: None
>> 22: height: root.theme_cls.standard_increment
23: padding: [root.theme_cls.horizontal_margins - dp(12), 0]
24: opposite_colors: True
...
AttributeError: 'NoneType' object has no attribute 'theme_cls'
File "C:\Users\kelleym\AppData\Local\Continuum\anaconda3\lib\site-packages\kivy\lang\builder.py", line 696, in _apply_rule
setattr(widget_set, key, value)
File "kivy\weakproxy.pyx", line 35, in kivy.weakproxy.WeakProxy.__setattr__
File "kivy\properties.pyx", line 497, in kivy.properties.Property.__set__
File "kivy\properties.pyx", line 544, in kivy.properties.Property.set
File "kivy\properties.pyx", line 599, in kivy.properties.Property.dispatch
File "kivy\_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
File "kivy\_event.pyx", line 1120, in kivy._event.EventObservers._dispatch
File "kivy\properties.pyx", line 1318, in kivy.properties.ReferenceListProperty.trigger_change
File "kivy\properties.pyx", line 1333, in kivy.properties.ReferenceListProperty.trigger_change
File "kivy\properties.pyx", line 599, in kivy.properties.Property.dispatch
File "kivy\_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
File "kivy\_event.pyx", line 1120, in kivy._event.EventObservers._dispatch
File "C:\Users\kelleym\AppData\Local\Continuum\anaconda3\lib\site-packages\kivymd\uix\behaviors\elevation.py", line 105, in _update_shadow
self._shadow = App.get_running_app().theme_cls.quad_shadow
File "C:\Users\kelleym\Desktop\Actual Inventory App\main.py", line 313, in <module>
sm.add_widget(inventory(name='inventory'))
我的代码:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivymd.theming import ThemeManager
Builder.load_string("""
<inventory>:
NavigationLayout:
id: "nav_layout"
MDToolbar:
title: "test"
MDNavigationDrawer:
drawer_logo: "test.png"
id: "nav_drawer"
NavigationDrawerSubheader:
text: "[color=#black]Categories[/color]"
NavigationDrawerIconButton:
icon: 'printer'
text: "Printers"
on_release: root.manager.current = 'printers'
NavigationDrawerIconButton:
text: "PCs"
icon: "laptop"
NavigationDrawerIconButton:
text: "Monitors"
icon: "monitor"
NavigationDrawerIconButton:
text: "Tablets"
icon: "tablet"
NavigationDrawerIconButton:
text: "Non-HP"
icon: "close-circle-outline"
NavigationDrawerIconButton:
text: "Supplies"
icon: "water"
NavigationDrawerIconButton:
text: "Misc."
icon: "paperclip"
Button:
text: "test"
on_release: app.nav_drawer.toggle()
""")
class inventory(BoxLayout, Screen):
pass
sm = ScreenManager()
sm.add_widget(inventory(name='inventory'))
class TestApp(App):
theme_cls = ThemeManager()
def build(self):
return sm
if __name__ == "__main__":
TestApp().run()
【问题讨论】:
标签: python kivy kivy-language