【问题标题】:Expansion panel is not expanding in kivymd扩展面板未在 kivymd 中扩展
【发布时间】:2020-05-20 19:06:29
【问题描述】:

我在 kivymd 中的 MDExpansionPanel 没有扩展我已经在 .kv 文件中编写了该代码

这是我的 .py 文件

from kivymd.app import MDApp


class TtApp(MDApp):
    pass


TtApp().run()

这是我的 .kv 文件

Screen:
    BoxLayout:
        orientation: "vertical"

        MDExpansionPanelTwoLine:
            text: ''
            secondary_text: 'email: xxxxx@gmail.com'

            IconLeftWidget:
                icon: "email"

        TwoLineAvatarListItem:
            text: ''
            secondary_text: 'to: @gmail.com'

            IconLeftWidget:
                icon: "email"

【问题讨论】:

    标签: kivy python-3.7 kivy-language expansion


    【解决方案1】:

    我让它工作了,我想你的设置方式是镜像的。

    看来您必须通过 Python 而不是 KV 语言来构建 MDExpansionPanel。此外,您必须为MDExpansionPanel 对象定义contentpanel_cls

    这是你的新main.py

    from kivymd.app import MDApp
    from kivymd.uix.boxlayout import MDBoxLayout
    from kivymd.uix.expansionpanel import MDExpansionPanel, MDExpansionPanelTwoLine
    from kivymd import images_path
    
    
    class Content(MDBoxLayout):
        pass
    
    
    class TtApp(MDApp):
    
        def on_start(self):
            self.root.ids.box.add_widget(
                MDExpansionPanel(
                    icon=f"{images_path}folder.png", # need an email .png here
                    content=Content(),
                    panel_cls=MDExpansionPanelTwoLine(
                        text='',
                        secondary_text='email: xxxxx@gmail.com',
                    )
                )
            )
    
    
    TtApp().run()
    

    这是你的新 tt.kv:

    <Content>:
        adaptive_height: True
    
        TwoLineAvatarListItem:
            text: ''
            secondary_text: 'to: @gmail.com'
    
            IconLeftWidget:
                icon: "email"
    
    Screen:
        BoxLayout:
            orientation: "vertical"
            id: box
    

    【讨论】:

    • 我知道这一点,但我想把它全部放在我的 tt.kv 文件中,我该怎么做
    • 我认为这是不可能的。我不记得错误信息了,但是当我尝试用 KV 语言做同样的事情时,它抱怨 panel_clsofficial example code for MDExpansionPanel 使用 Python 而不是 KV,我无法在 KV 中定义的 panel_cls 的网络上找到单个示例。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多