Home > kivy, multitouch, python > Kivy – Multiple Layouts

Kivy – Multiple Layouts

September 14th, 2011 Leave a comment Go to comments

I wonder how can I have several layouts and change between them using kv files in kivy. Actually I have the answer.

You have to create an ejercicio.kv file. You have to define the classes you are going to use for each layout such as.

#:kivy 1.0

<MyLabelWithBackground>:
       #definition

<Ejercicio>:
      #definition

<Layout1>:
      #definition

<Layout2>:
      #definition

Once we have our definitions for each layout, we have to implement the python part and create classes for each definition.

import kivy
kivy.require(‘1.0.7’)

from kivy.uix.floatlayout import FloatLayout
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.app import App

class Ejercicio(FloatLayout):
    def do_action(self):
        pass

class Layout1(FloatLayout):
def do_action(self):
pass

class Layout2(FloatLayout):
     def do_action(self):
         pass

class MyLabelWithBackground(Label):
    pass

class EjercicioApp(App):
    def build(self):
parent = Widget()
        #a = Ejercicio(size=(1024, 768))
b = Layout1(size=(1024, 768))
        #c = Layout2(size=(1024, 768))
        #d = MyLabelWithBackground(text=”Hola mundo”)
parent.add_widget(b)
        #parent.add_widget(a)
        #parent.add_widget(c)
        return parent

if __name__ in (‘__android__’, ‘__main__’):
EjercicioApp().run()

You can change between each definition uncomment the source.

Categories: kivy, multitouch, python Tags: , , ,
  1. No comments yet.
  1. No trackbacks yet.