You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

向MDNavigationDrawer添加项时出现Unknown class <DrawerClickableItem>错误

解决KivyMD中“Unknown class ”错误

问题出在你用了错误的组件名称——KivyMD里根本没有DrawerClickableItem和DrawerLabelItem这两个类,正确的导航项组件是MDNavigationDrawerItem,通过type属性来定义不同类型的导航项。

修改后的KV文件代码

MDScreen:
    name: 'home'
    md_bg_color: 1, 1, 1, 1
    background_normal: ''

    MDNavigationLayout:
        ScreenManager:
            Screen:
                BoxLayout:
                    orientation: 'vertical'
                    MDTopAppBar:
                        md_bg_color: [0, 0, 0, 1]
                        elevation: 2.5
                        title: "Home"
                        left_action_items: [['menu', lambda x: nav_drawer.set_state("open")]]

                    Widget:


        MDNavigationDrawer:
            id: nav_drawer
            size_hint: .3, .9
            radius: (0, 30, 30, 0)
            md_bg_color: 0, 0, 0, 1
            pos_hint: {'y': .1}
            scrim_color: 0, 0, 0, 0

            MDNavigationDrawerMenu:

                MDNavigationDrawerHeader:
                    title: "Header title"
                    title_color: "#4a4939"
                    text: "Header text"
                    spacing: "4dp"
                    padding: "12dp", 0, 0, "56dp"

                MDNavigationDrawerLabel:
                    text: "Mail"

                MDNavigationDrawerItem:
                    type: "clickable"
                    icon: "gmail"
                    right_text: "+99"
                    text_right_color: "#4a4939"
                    text: "Inbox"

                MDNavigationDrawerItem:
                    type: "clickable"
                    icon: "send"
                    text: "Outbox"

                MDNavigationDrawerDivider:

                MDNavigationDrawerLabel:
                    text: "Labels"

                MDNavigationDrawerItem:
                    type: "label"
                    icon: "information-outline"

关键修改点

  • 把所有DrawerClickableItem替换成MDNavigationDrawerItem,并添加type: "clickable"属性,这是可点击的导航项类型
  • 把DrawerLabelItem替换成MDNavigationDrawerItem,并添加type: "label"属性,这是仅展示的标签类型
  • 原有的icon、right_text等属性完全兼容MDNavigationDrawerItem,不需要额外修改

Python代码无需改动,直接运行即可解决“Unknown class”的报错问题。

内容的提问来源于stack exchange,提问作者Signore

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 10:55:21