0

For example we created with kivy language simple BoxLayout1 that contains button1 and another BoxLayout2. When you click button1 it adds a new button in BoxLayout2 but it's written in python.

Is it possible to acces existing layout in kv language, in python code? Or only solution is writting whole window in python?

I couldn't find any info in kivy docs, maybe I've just missed something.

EDIT:

I've something like this

Kv:

<CreateWindow>:
    BoxLayout:
        Button:
              text: "test"
              on_release: root.press()
    BoxLayout:
        Label:
              text: "Label"

Python:

class CreateWindow(Screen):
      def press(self):

I want to add a new button near Label by activating press function

3
  • In general you are free to mix and match python and kv as much as you like, and you can expect that it's easy to communicate between widgets created in either. This blog post discusses various methods. Commented Aug 29, 2021 at 18:21
  • can add some runnable code so we can help you Commented Aug 29, 2021 at 18:24
  • I think the blog post that @inclement sent is the solution i'll definitely check it out but if you know solution to my problem, go ahead and add it! Commented Aug 29, 2021 at 18:39

1 Answer 1

1

in python will be like this


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())
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.