Home > Net >  kivy.factory.FactoryException: Unknown class <MDTopAppBar>
kivy.factory.FactoryException: Unknown class <MDTopAppBar>

Time:07-17

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.

CodePudding user response:

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()

CodePudding user response:

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}
  • Related