Wilko84
Wilko84

Reputation: 131

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?

Upvotes: 3

Views: 5016

Answers (4)

farisfath25
farisfath25

Reputation: 93

I guess you're using the "latest" version it should be version 2.x.y something

I also met the same problem, so I tried to use the following: (after several attempts tho)

from kivymd.uix.appbar import MDTopAppBar

yeah it worked for me hope it helps

reference: [Appbar - KivyMD Documentation][1]

Upvotes: 0

VIGNESH C
VIGNESH C

Reputation: 3

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

Upvotes: 0

Cecil Curry
Cecil Curry

Reputation: 10286

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.

Upvotes: 0

GreNait
GreNait

Reputation: 113

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.

Upvotes: 1

Related Questions