I am trying to use kivymd using this code :
from kivy.app import App
from kivymd.theming import ThemeManager
from kivymd.navigationdrawer import MDNavigationDrawer
from kivymd.navigationdrawer import NavigationLayout
from kivymd.card import MDSeparator
class MyApp(App):
theme_cls=ThemeManager()
if __name__ == "__main__":
m = MyApp()
m.run()
but im getting this error :
from kivymd.navigationdrawer import MDNavigationDrawer
ModuleNotFoundError: No module named 'kivymd.navigationdrawer'
>>>
This is my kv file :
#:import NavigationLayout kivymd.navigationdrawer.NavigationLayout
#:import MDSeparator kivymd.card
NavigationLayout:
MDNavigationDrawer:
<Button>:
text: "Hey"
Can someone help me with this ?
EXPLANATION -- PLEASE READ:
You're using some code that was made for an older version of KivyMD. In new versions, most widgets have been moved to the kivymd.uix
folder, so you would change #:import NavigationLayout kivymd.navigationdrawer.NavigationLayout
to #:import NavigationLayout kivymd.uix.navigationdrawer.NavigationLayout
(and similar for all other widgets. BUT, all KivyMD widgets are automatically recognized in kv
files as long as you have from kivymd.app import MDApp
in your main.py
file. (In Python you would still need to write from kivymd.uix.navigationdrawer import MDNavigationDrawer
or whatever if you need to access the class in Python).
SOLUTION:
main.py
:
from kivymd.app import MDApp
class MyApp(MDApp):
pass
if __name__ == "__main__":
m = MyApp()
m.run()
my.kv
:
NavigationLayout:
MDNavigationDrawer:
Button:
text: "Hey"