发布
社区首页 >问答首页 >Python库添加小部件

Python库添加小部件
EN

Stack Overflow用户
提问于 2021-08-29 18:05:23
回答 1查看 58关注 0票数 0

例如,我们使用kivy语言创建了包含button1和另一个BoxLayout2的简单BoxLayout2。单击button1时,它在BoxLayout2中添加了一个新按钮,但它是用python编写的。

是否有可能以kv语言在python代码中访问现有布局?还是只有解决方案在python中写入整个窗口?

我在奇维的文档里找不到任何信息,也许我只是漏掉了什么。

编辑:

我有这样的东西

Kv:

代码语言:javascript
代码运行次数:0
复制
<CreateWindow>:
    BoxLayout:
        Button:
              text: "test"
              on_release: root.press()
    BoxLayout:
        Label:
              text: "Label"

Python:

代码语言:javascript
代码运行次数:0
复制
class CreateWindow(Screen):
      def press(self):

我想通过激活函数在标签附近添加一个新按钮

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-29 21:47:21

在蟒蛇里会是这样

代码语言:javascript
代码运行次数:0
复制
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())
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68975657

复制
相关文章

相似问题

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