'KivyMD TopAppBar

I'm trying to learn Kivy and KivyMD because I want to make an android app.

But I'm stuck at the first hurdle. I want a toolbar, or as the KivyMD documentation calls it, a TopAppBar.

I'm trying to implement it as per the doc's, but I get an error Unknown Class <MDTopAppBar>

I though maybe that I had mistyped something, so I copied and pasted the entire code example from the docs and the error still persists. As far as I am aware, I am running the latest version of Kivy & KivyMD

Code from docs:

from kivy.lang import Builder

from kivymd.app import MDApp

KV = '''
MDBoxLayout:
    orientation: "vertical"

    MDTopAppBar:
        title: "MDTopAppBar"

    MDLabel:
        text: "Content"
        halign: "center"
'''


class Test(MDApp):
    def build(self):
        return Builder.load_string(KV)


Test().run()

My code:

from kivymd.app import MDApp
from kivy.lang import Builder


KV = '''
MDBoxLayout:

    MDTopAppBar:
        title: "World Pool Rules"
'''


class MyApp(MDApp):
    def build(self):
        return Builder.load_string(KV)


if __name__ == '__main__':
    MyApp().run()

I've also tried from kivymd.uix.topappbar import MDTopAppBar but just get a No module named error.

Any help would be much appreciated

Anyone know how I can fix this?



Solution 1:[1]

I recently had the same issue. I was looking through the official documentation and saw, that the documentation was referencing version 1.0.0-dev. However, I had installed via pypi version: 0.104.2 (latest official version - I guess?)

https://pypi.org/project/kivymd/

After changing the documentation to the right version:

https://kivymd.readthedocs.io/en/0.104.2/index.html

I saw that there is no "MDTopBar". You will need to use just "MDToolbar" instead.

Solution 2:[2]

According to commentary on this issue thread by the principal developer of KivyMD, the location-specific suite of MD{Bottom,Top}AppBar widgets is a recent addition that has yet to be officially released. Presumably, these widgets will be published with the next stable release (e.g., KivyMD 0.104.3).

To access them now anyway, manually install the live version of KivyMD from its GitHub-hosted git repository. Thanks to the magic of modern pip, this one-liner gets you there and back again: e.g.,

pip install git+https://github.com/kivymd/KivyMD.git

KivyMD's "latest" documentation is, in fact, its unstable documentation. This is why we can't have good things.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DharmanBot
Solution 2 Cecil Curry