kivy中的引用模板(?)小部件

2024-09-27 09:29:53 发布

您现在位置:Python中文网/ 问答频道 /正文

让我们在我的kv文件中说,我这样做

<BigButton@Button>:
    text: "demo"
    some_other_things: True

如何在py中添加此小部件?这不起作用:

someWidget=self.ids.someWidgetID
TestButton=BigButton(some_other_other_things=False)
someWidget.add_widget(TestButton)

它抛出一个未定义BigButton的名称错误

谢谢你的帮助


Tags: 文件textpyselftruedemo部件button
1条回答
网友
1楼 · 发布于 2024-09-27 09:29:53

回答我自己的问题: 要创建此类小部件,请使用Factory

from kivy.factory import Factory

someParentWidget = self.ids.someParentWidgetID

TestButton = Factory.BigButton()
TestButton.some_other_other_thing=True
someParentWidget.add_widget(TestButton)

相关问题 更多 >

    热门问题