【发布时间】:2019-04-13 18:06:54
【问题描述】:
我正在尝试 Kivymd,但不断收到错误消息:AttributeError: 'NoneType' object has no attribute 'theme_cls'。
我在 App 类中添加了 theme_cls = ThemeManager() 但仍然收到错误消息。请帮忙,因为没有更多的在线解决方案。
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition, WipeTransition
from kivy.app import App
from kivy.uix.button import Button
from kivymd.navigationdrawer import MDNavigationDrawer
from kivymd.theming import ThemeManager
class BeginScreen(Screen):
pass
class MyScreenManager(ScreenManager):
pass
Login = Builder.load_string('''
#: import Toolbar kivymd.toolbar.Toolbar
MyScreenManager:
Screen:
<Screen>:
Toolbar:
title: "Simple toolbar"
pos_hint: {'center_x': 0.5, 'center_y': 0.75}
md_bg_color: get_color_from_hex(colors['Teal']['500'])
background_palette: 'Teal'
background_hue: '500'
Toolbar:
title: "Toolbar with right buttons"
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
md_bg_color: get_color_from_hex(colors['Amber']['700'])
background_palette: 'Amber'
background_hue: '700'
right_action_items: [['content-copy', lambda x: None]]
Toolbar:
title: "Toolbar with left and right buttons"
pos_hint: {'center_x': 0.5, 'center_y': 0.25}
md_bg_color: get_color_from_hex(colors['DeepPurple']['A400'])
background_palette: 'DeepPurple'
background_hue: 'A400'
left_action_items: [['arrow-left', lambda x: None]]
right_action_items: [['lock', lambda x: None], \
['camera', lambda x: None], \
['play', lambda x: None]]
''')
class MyApp(App):
theme_cls = ThemeManager()
def build(self):
return Login
if __name__ == "__main__":
MyApp().run()
【问题讨论】:
-
你用的是什么版本的python和kivymd?