KVLang Series – 3

KVLang Series – 3

← Previous              Next →

More Widgets in a BoxLayout


  • .kv file
  • .py file
  • screenshot of output


In the .kv file we add some more widgets under a BoxLayout.
If we added the widgets directly to the file, not being underneath our layout, it would be and ERROR because they would be considered root rules and “you can have one root rule, and any number of class or template rules.”
The BoxLayout has a default orientation: ‘horizontal’.

### 0003_moreWidgets.kv

        text: 'Input:'
        text: 'Default Text'
        text: 'Press Me'


This is adapted from previous python file. We make minor changes to update the .kv filename and give a new window height.

  1. EDIT

    CHANGE: The OLD self.root = Builder.load_file(”) TO the NEW

  2. EDIT

    WAS: Config.set(‘graphics’, ‘height’, ‘200’)

    NOW: Config.set(‘graphics’, ‘height’, ’30’)

''' 0003_moreWidgets.py
Used to display 0003_moreWidgets.kv - No new concepts in here.
import kivy
kivy.require('1.8.0') # replace with your current kivy version !

from kivy.app import App
from kivy.lang import Builder
from kivy.config import Config

Config.set('graphics', 'width',  '323')
Config.set('graphics', 'height', '30')

class MyApp(App):

    def build(self):
        self.root = Builder.load_file('0003_moreWidgets.kv')
        return self.root

if __name__ == '__main__':

0003_moreWidgets ScreenShot

Here is what this looks like run on Windows XP. In Pixels, it has:

  • width: 323
  • height: 200

Alt 0003_moreWidgets.png

#examples, #gui, #kivy, #kvlang, #python, #tutorial