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

Kivy – Multiple Layouts

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.

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: