首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Kivy [widget]没有属性[child_widget]

Kivy [widget]没有属性[child_widget]
EN

Stack Overflow用户
提问于 2015-12-22 13:48:28
回答 1查看 261关注 0票数 0

我正在尝试使用remove_widget函数使我的按钮在被单击后消失。根据documentation的说法,我认为这是实现这一目标的正确方法。然而,当我试图移除按钮时,我得到了崩溃。不确定这是否与对小部件的引用类型或其他什么有关。

这是我的main.kv

代码语言:javascript
复制
<MainPanel>:
orientation: 'vertical'
spacing: 1

AppActionBar:
    size_hint: (1., 0.1)

ScrollView:
    id: scrollview_main
    do_scroll_x: False
    do_scroll_y: False if root.fullscreen else (content.height > root.height - dp(16))
    AnchorLayout:
        id: anchorlayout_main
        size_hint_y: None
        height: root.height if root.fullscreen else max(root.height, content.height)
        GridLayout:
            id: content
            cols: 1
            spacing: '8dp'
            padding: '8dp'
            size_hint: (1, 1) if root.fullscreen else (.8, None)
            height: self.height if root.fullscreen else self.minimum_height
            Button:
                id: button_open_process
                size_hint_y: None
                text: 'Open New Process'
                height: '48dp'
                width: '120dp'
                on_release:
                    root.open_process()
                    root.remove_widget(root.button_attach_process) <-- offending line
                    #root.remove_widget(root.button_open_process)
            Button:
                id: button_attach_process
                size_hint_y: None
                text: 'Attach to Currently Running Process'
                height: '48dp'
                width: '120dp'
                on_release: root.attach_process()

和我在单击id为button_open_process的按钮时得到的错误

代码语言:javascript
复制
AttributeError: 'MainPanel' object has no attribute 'button_attach_process'

导致此问题的原因是什么?

EN

回答 1

Stack Overflow用户

发布于 2015-12-22 20:44:02

在kv中管理动态小部件有点笨拙,但无论如何,问题是设置id不会设置根小部件的属性-这就是它不存在的原因。相反,您可以直接使用root.remove_widget(button_attach_process)root.remove_widget(root.ids.button_attach_process),这也可以在python文件中使用。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34409244

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档