3

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?

Wilko84
  • 81
  • 1
  • 6

3 Answers3

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.

DharmanBot
  • 1,066
  • 2
  • 6
  • 10
GreNait
  • 103
  • 1
  • 8
  • **Yikes.** I just hit this as well. Certainly, replacing the location-specific suite of `MD{Bottom,Top}AppBar` widgets with a single location-agnostic `MDToolbar` is sensible. What's insensible is that the RTD-hosted documentation for KivyMD labelled "latest" is, in fact, outdated; you have to manually select the documentation for the newest stable release to view the *real* latest API. `` – Cecil Curry May 14 '22 at 04:53
  • **Oh. I see.** According to [commentary on this issue thread by the principal developer of KivyMD](https://github.com/kivymd/KivyMD/issues/1228#issuecomment-1100962034), the single location-agnostic `MDToolbar` widget has indeed been replaced with the location-specific suite of `MD{Bottom,Top}AppBar` widgets. The catch? This new API has yet to be officially released. You need to [manually install the live version of KivyMD from its GitHub-hosted `git` repository](https://github.com/kivymd/KivyMD). KivyMD's "latest" documentation is, in fact, its unstable documentation. – Cecil Curry May 14 '22 at 04:59
0

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.

Cecil Curry
  • 9,789
  • 5
  • 38
  • 52
0

Instead of adding MDTopAppBar into a MDBoxLayout, you can try using MDScreen instead. That would work I guess. I have created various apps using MDTopAppBar but did not get any error as you have mentioned.

.KV code

MDScreen:
  MDTopAppBar:
    title: "World Pool Rules" 

Else you can re-install kivy, kivymd using pip install kivymd

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
VIGNESH C
  • 3
  • 3