例如,我们使用kivy语言创建了包含button1和另一个BoxLayout2的简单BoxLayout2。单击button1时,它在BoxLayout2中添加了一个新按钮,但它是用python编写的。
是否有可能以kv语言在python代码中访问现有布局?还是只有解决方案在python中写入整个窗口?
我在奇维的文档里找不到任何信息,也许我只是漏掉了什么。
编辑:
我有这样的东西
Kv:
<CreateWindow>:
BoxLayout:
Button:
text: "test"
on_release: root.press()
BoxLayout:
Label:
text: "Label"
Python:
class CreateWindow(Screen):
def press(self):
我想通过激活按函数在标签附近添加一个新按钮
发布于 2021-08-29 21:47:21
在蟒蛇里会是这样
class CreateWindow(Screen):
def press(self):
# the first box is the first child in the children list of the CreateWindow widget so
box1=self.children[0]
box2=self.children[1]
# and now you can decide which box you want to use add_widget method with
# in your case it should be
box2.add_widget(Button())
https://stackoverflow.com/questions/68975657
复制相似问题