Answer the question
In order to leave comments, you need to log in
How to call another layout from a layout?
Hello.
According to the kivy application design, the layout is called via the build method. But I can't figure out how to change the displayed layout.
Tell me how to change the layouts displayed on the screen.
Using the code example, how can I change the layout of Window1 to Window2 by clicking on the button1 button?
import kivy
kivy.require('1.11.1')
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
class Window1(FloatLayout):
def __init__(self, **kwargs):
super(Window1, self).__init__(**kwargs)
label = Label(text='label1', pos_hint={'center_x':.5, 'center_y':.6})
button = Button(text='btn1', pos_hint={'center_x':.5, 'center_y':.4},
size_hint=(.4, .3))
self.add_widget(label)
self.add_widget(button)
class Window2(FloatLayout):
def __init__(self, **kwargs):
super(Window2, self).__init__(**kwargs)
label = Label(text='label2', pos_hint={'center_x':.5, 'center_y':.7})
button = Button(text='btn2', pos_hint={'center_x':.5, 'center_y':.3},
size_hint=(.4, .3))
self.add_widget(label)
self.add_widget(button)
class App(App):
def build(self):
return Window1()
App().run()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question