Layouts in layouts (Multiple Layouts) in Kivy Python (original) (raw)

Last Updated : 13 Jan, 2026

Multiple layouts in Kivy means placing one layout inside another to create structured and organized screens. This is used when different parts of the screen need different layout behaviors such as rows, columns or fixed positions.

This program displays a TextInput box placed inside a BoxLayout to show how a layout can hold widgets.

Python `

from kivy.app import App from kivy.uix.boxlayout import BoxLayout from kivy.uix.textinput import TextInput

class MyApp(App): def build(self): a = BoxLayout() s = TextInput(text="Enter name") a.add_widget(s) return a

MyApp().run()

`

**Output:

MultipleLayout

A text input box appears inside the Kivy window.

**Explanation:

Syntax:

ParentLayout(parameters):
ChildLayout(parameters):
Widget(parameters)

A parent layout holds one or more child layouts, and each child layout can hold widgets.

**Parameters:

Examples

**Example 1: This code places a BoxLayout inside a FloatLayout to position grouped widgets freely.

Python `

from kivy.app import App from kivy.uix.floatlayout import FloatLayout from kivy.uix.boxlayout import BoxLayout from kivy.uix.button import Button

class MyApp(App): def build(self): f = FloatLayout() b = BoxLayout(size_hint=(.5, .3), pos_hint={'x': .25, 'y': .4}) b.add_widget(Button(text="A")) b.add_widget(Button(text="B")) f.add_widget(b) return f

MyApp().run()

`

**Output:

Output1

Two buttons appear inside a centered box layout.

**Explanation:

**Example 2: This code places a centered button inside a BoxLayout using AnchorLayout.

Python `

from kivy.app import App from kivy.uix.boxlayout import BoxLayout from kivy.uix.anchorlayout import AnchorLayout from kivy.uix.button import Button

class MyApp(App): def build(self): b = BoxLayout() a = AnchorLayout(anchor_x='center', anchor_y='center') a.add_widget(Button(text="Center")) b.add_widget(a) return b

MyApp().run()

`

**Output:

Output2

A button appears at the center of the window.

**Explanation: