【问题标题】:How to create the duplicate widget?如何创建重复的小部件?
【发布时间】:2019-06-28 09:44:42
【问题描述】:

我正在尝试使用已创建的小部件的属性创建新的 TabbedPanelItem。但我得到新的空小部件或替换存在。

.py

    class MainScreen(Screen):
        def add(self, tabbed_item):
            new_tabbed_item = TabbedPanelItem()
            new_tabbed_item.properties = copy(tabbed_item)
            new_tabbed_item.text = "2"
            self.ids.tab_panel.add_widget(new_tabbed_item)

.kv

    <MainScreen>:
        AnchorLayout:
            canvas.before:
                ...     
            TabbedPanel:
                id: tab_panel
                ...

                TabbedPanelItem:
                    Button:
                        on_press: root.add(tab_item)


                TabbedPanelItem:
                    id: tab_item
                    ....

【问题讨论】:

    标签: python python-3.x widget kivy


    【解决方案1】:

    当我尝试运行你的代码时,什么也没有弹出。您没有足够的代码进行测试。我不确定你的目标是什么,但如果你想拥有一个 TabbedPanelItem 已经创建的东西而不必重现相同的代码(如果这是你的目标),请尝试使用 @。一个例子:MyTabbedPanel@TabbedPanelItem:。然后,您可以添加您希望它执行的所有操作,并重复使用它,而不是每次都重新输入代码。

    【讨论】:

    • 这有帮助吗?
    猜你喜欢
    • 1970-01-01
    • 2013-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-29
    • 2020-01-23
    • 1970-01-01
    • 2021-12-03
    相关资源
    最近更新 更多