Table of contents
1.
Introduction
2.
PageLayout
3.
Approach:
4.
Code
5.
Output 
6.
Demo video
7.
FAQs
7.1.
What is the application of kivy?
7.2.
Can we implement the page layout in kivy without using python language?Yes, we can use the .kv file to implement the page layout in kivy.
7.3.
What is the use of Page Layout?
8.
Conclusion
Last Updated: Mar 27, 2024
Easy

PageLayout

Author Apoorv
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Kivy is an open-source framework in Python for designing applications. Kivy is also a platform-independent graphical user interface tool in Python. Anchor Layout, BoxLayout, FloatLayout, RelativeLayout, GridLayout, PageLayout, ScatterLayout, and StackLayout are some of the layouts available in Kivy. In this article, we will see the Relative Layout in detail. 

PageLayout

  • The PageLayout differs from other layouts in how it functions. It's a dynamic layout in the sense that its borders can be used to flick across pages. The concept is that its components are layered in front of each other, with just the top one visible.
  • The PageLayout class is used to make a simple multi-page layout with a border that makes it easy to flip from one page to the next.
  • PageLayout currently does not honor the size_hint, size_hint_min, size_hint_max, or pos_hint properties.This means we can not use all these in a page layout.

To use PageLayout first you must import it with the following command:

  from kivy.uix.pagelayout import PageLayout

You can refer to the official documentation of the page layout from here.

Approach:

  1. Install kivyApp
    Use this command to install kivy on a local PC in the command prompt
    python -m pip install kivy[full]
  2. Import kivy in the python file
  3. Import Pagelayout 
  4. Configure the minimum version (optional)
  5.  Make an App class.
  6. Layout/widget/Class should be returned (according to requirement)
  7. Create a class instance.
  8. To finally run, use this command in the command prompt 
    python file_name.py 

For my case, it would look like this

Code

File Name in my case is kivysamplerun

# This is Sample Python application showing
# the working of RelativeLayout in Kivy
 
# Module imports  
import kivy
   
# base Class of your main App is inherited from the App class.
# app:Here app refers to the particular instance of your program or application
from kivy.app import App
 
# The PageLayout differs from other layouts in how it functions.
# It's a dynamic layout in the sense that its borders can be used to flick across pages.
from kivy.uix.pagelayout import PageLayout
 
# creates the button in kivy
# if it is not imported the it will show the error
from kivy.uix.button import Button

# we use this module config to change the default settings of Kivy
from kivy.config import Config
     
# 0 being off 1 being on
Config.set('graphics', 'resizable', 1)
   
class PageLayout(PageLayout):
   
    # Define class PageLayout here
    # Constructor
    def __init__(self):
         
        # In Python, the super function can be used to get access
        # to inherited methods from either a parent or sister class.
        super(PageLayout, self).__init__()
 
        # creating of buttons
        button1 = Button(text ='This is page1')
        button2 = Button(text ='This is page2')
        button3 = Button(text ='This is page3')
 
        # adding button on the screen by using widget
        self.add_widget(button1)
        self.add_widget(button2)
        self.add_widget(button3)
 
 
# creating the App class
class Page_LayoutDemo(App):
   
    # App class here
 
    def build(self):
        # building function here
        return PageLayout()
 

# creating the object root for PageLayoutApp() class  
Application = Page_LayoutDemo()
# Run the Kivy app
Application.run()
You can also try this code with Online Python Compiler
Run Code

Output 

Demo video

Watch here

FAQs

What is the application of kivy?

Kivy is a Python-based multi-platform application development framework. It enables us to create cross-platform programs for Windows, Linux, Android, macOS, iOS, and the Raspberry Pi.

Can we implement the page layout in kivy without using python language?
Yes, we can use the .kv file to implement the page layout in kivy.

What is the use of Page Layout?

The PageLayout class is used to make a simple multi-page layout with boundaries that make it easy to flip from one page to the next.

Conclusion

In this article, we have extensively discussed PageLayout in kivy.You can check out the entire study plan for big data from here. To read the introduction of Hadoop and its ecosystem you can refer to this. If you are willing to learn more about databases you can refer to this

 

"We hope that this blog has helped you enhance your knowledge regarding this problem, and if you would like to learn more, check out our articles on  Coding Ninjas Studio. To be more confident in data structures and algorithms, try out our DS and Algo Course. For interview experiences, you can refer here. We have various guided paths for various theory subjects like DBMS, OS, and Aptitude you can check out this from here. You can give the various mock tests to excel your interview preparation from here. Do upvote our blog to help other ninjas grow. Happy Coding!”

Live masterclass