KVLang Series – 3 – More Widgets in a BoxLayout

KVLang Series – 3

← Previous              Next →

More Widgets in a BoxLayout

Content:
– .kv file
– .py file
– screenshot of output

0003_moreWidgets.kv

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

BoxLayout:
    Label:
        text: 'Input:'
    TextInput:
        text: 'Default Text'
    Button:
        text: 'Press Me'

0003_moreWidgets.py

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

''' 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.core.window import Window
Window.size = (323,30)

class MyApp(App):

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

if __name__ == '__main__':
    MyApp().run()

0003_moreWidgets ScreenShot

Here is what this looks like run on Windows XP. In Pixels, it has:
– width: 331
– height: 64

Alt 0003_moreWidgets.png

Advertisements

2 thoughts on “KVLang Series – 3 – More Widgets in a BoxLayout

    • Dear Hector,
      Frankly, I have NO EARTHLY IDEA why this is happening to you. :)
      Perhaps it’s an installation issue.
      I tested this on OS: Windows XP-SP3, Kivy Version: 1.8.0 stable, Installation Type: “portable package”, Kivy App Start Type: “Send-to method”. See [Kivy] Installation on Windows.
      It DOESN’T BLINK at me. :)
      Sorry I can’t be of any further help.
      Please, if you find out what’s happening, please post a response here.
      Thanks, Hector.

      Love and peace,
      Joe

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