2

This is might be a naive question as I'm learning Kivy these days. Pardon me if I'm asking silly question. I'm trying to use MDTopAppBar but getting an error which says

 kivy.factory.FactoryException: Unknown class <MDTopAppBar>

Here is my code

<Screen2>:
    name: 'Screen1'
    MDBoxLayout:
        orientation: 'vertical'

        MDTopAppBar:
            title: 'Demo App'
            pos_hist: {'center_x': 0.5, 'center_y': 1}
        

Kivymd version = 0.104.2

Could you please help me with this.

Swati
  • 43
  • 1
  • 5
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jul 17 '22 at 09:25
  • added my code in the question. please look – Swati Jul 17 '22 at 09:41
  • Please look if this answers your question https://stackoverflow.com/questions/72025912/kivymd-topappbar/72026973#72026973 – Sachin Dev Sharma Jul 17 '22 at 09:45

4 Answers4

1

You should use MDToolbar instead of MDTopAppBar. Here is an example:

from kivy.lang import Builder

from kivymd.app import MDApp

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

    MDToolbar:
        title: "MDTopAppBar"

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


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


Test().run()
DXNI
  • 149
  • 14
1

As you said, you are using KivyMD 0.104.2. The latest documentation version, probably the one you used to write this code, is 1.0.0.dev0. As of v1.0.0, MDToolbar was renamed to MDTopAppbar.

There are 2 ways to solve this problem.

  1. Install the latest version of KivyMD (I recommend doing this, as long as you are fine working on an in-development version)

If you want to install development version from master branch, you should specify link to zip archive:

pip install https://github.com/kivymd/KivyMD/archive/master.zip

Tip: Replace master.zip with <commit hash>.zip (eg 51b8ef0.zip) to download KivyMD from specific commit.

  1. Change MDTopAppBar to MDToolbar in your code.
<Screen2>:
    name: 'Screen1'
    MDBoxLayout:
        orientation: 'vertical'

        MDToolbar:
            title: 'Demo App'
            pos_hint: {'center_x': 0.5, 'center_y': 1}
1

In kivyMD the toolbar has changed. There is only a MDTopAppBar or the MDBottomAppBar. Read more

Screen: 
    BoxLayout:
        orientation: 'vertical'
        MDTopAppBar: 
            title: 'Demo'
            left_action_items: [['menu', lambda x: app.navigation_draw()]]
            right_action_items: [['clock', lambda x: app.navigation_draw()]]
            elevation: 10
        MDLabel:
            text: 'Hello World'
            halign: 'center'   
Abhijith M
  • 743
  • 5
  • 5
1

Replace MDToolbar with MDTopAppBar this will easily fix the issue. Hope it helps someone.

AKKJ
  • 11
  • 2