【问题标题】:how do i use MDDropdownMenu with an iconbutton KivyMD?我如何使用带有图标按钮 KivyMD 的 MDDropdownMenu?
【发布时间】:2021-10-06 14:41:07
【问题描述】:

我想制作一个与图标按钮连接的下拉菜单,单击该按钮将显示一个确认对话框。但是当我点击图标按钮打开对话框时,这个错误信息

MDDropdownMenu() takes no arguments

弹出。这是我第一次制作下拉列表,我还是个新手,所以我不知道该怎么做。

代码

def drop_down(self):
    self.dropdown = MDDropdownMenu()
    dropmenu = self.root.ids['Chat_Screen'].ids['dropdown']
    self.dropdown = MDDropdownMenu(dropmenu = dropmenu, items=[{"viewclass": "MDMenuItem", "text": "option1"}], width_mult=4)
    self.dropdown.open()

这是在 MDApp 类中

.kv 文件

MDIconButton:
                #icon: 'phone-outline'
                id:LIST
                name:'LIST'
                theme_text_color: 'Custom'
                text_color: app.theme_cls.primary_color
                user_font_size: 16
                size_hint: (None, None)
                pos_hint: {'center_y':.5}
                size: 30, 30
                padding: 0
                md_bg_color: app.theme_cls.bg_darkest if app.theme_cls.theme_style == 'Light' else app.theme_cls.bg_dark
            MDIconButton:
                id: dropdown
                icon: 'dots-vertical'
                theme_text_color: 'Custom'
                text_color: app.theme_cls.primary_color
                user_font_size: 20
                size_hint: (None, None)
                pos_hint: {'center_y':.5}
                size: 30, 30
                padding: 0
                md_bg_color: app.theme_cls.bg_darkest if app.theme_cls.theme_style == 'Light' else app.theme_cls.bg_dark
                on_press: app.drop_down()
                

【问题讨论】:

    标签: python python-3.x kivy kivymd


    【解决方案1】:

    尝试改变:

    self.dropdown = MDDropdownMenu(dropmenu = dropmenu, items=[{"viewclass": "MDMenuItem", "text": "option1"}], width_mult=4)
    

    到:

    self.dropdown = MDDropdownMenu(caller=dropmenu, items=[{"viewclass": "MDMenuItem", "text": "option1"}], width_mult=4)
    

    【讨论】:

    • 还是同样的问题'MDDropdownMenu() 没有参数'
    猜你喜欢
    • 2021-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-21
    • 1970-01-01
    相关资源
    最近更新 更多