Reputation: 321
I'm having trouble getting KivyMD working, I've read so many of the questions on here about this error but none of them have worked. The below is a minimum runnable example, I know the issue is with the code in the MyApp class but I don't know exactly why it isn't working. Thanks in advance for your help
main.py
import kivy
from kivy.app import App
from kivy.properties import ObjectProperty, StringProperty, NumericProperty, ListProperty
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang import Builder
from kivy.uix.popup import Popup
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.core.window import Window
from kivymd.theming import ThemeManager
import mysql.connector
Window.clearcolor = (1,1,1,1)
class Information(Screen):
pass
class WindowManager(ScreenManager):
pass
kv = Builder.load_file("kivy.kv")
sm = WindowManager()
screens = [Information(name="information")]
for screen in screens:
sm.add_widget(screen)
sm.current = "information"
class MyApp(App):
theme_cls = ThemeManager()
def build(self):
return sm
if __name__ == '__main__':
MyApp().run()
kivy.kv
<Information>:
name: "information"
FloatLayout:
ActionBar:
pos_hint: {'top': 1}
ActionView:
background_image: ""
background_color: 0.2,0.6,1,1
ActionPrevious:
app_icon: "white menu.png"
with_previous: False
ActionOverflow:
ActionButton:
app_icon: "close.png"
on_release: print("Button pressed")
MDRaisedButton:
text: "Test"
Full Error
AttributeError: 'NoneType' object has no attribute 'theme_cls'
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\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\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivymd\uix\elevation.py", line 126, in _update_shadow
self._shadow = App.get_running_app().theme_cls.quad_shadow
Upvotes: 1
Views: 490
Reputation: 38937
You just need to do your Builder.load_file()
after the MyApp
class is defined. You can move it inside the build()
method:
class MyApp(App):
theme_cls = ThemeManager()
def build(self):
kv = Builder.load_file("kivy.kv")
sm = WindowManager()
screens = [Information(name="information")]
for screen in screens:
sm.add_widget(screen)
sm.current = "information"
return sm
if __name__ == '__main__':
MyApp().run()
Upvotes: 1