newbiemobile
newbiemobile

Reputation: 21

How to create simple Kivy app (form with field name)

How to create simple Kivy app?

If user type text into field "Name" using keyboard like on android phone, this name is display

I need this to learn

Upvotes: 0

Views: 13785

Answers (1)

Here's as simple an example as i can figure out.

Here's the KVLANG code.

<LblTxt@BoxLayout>:
    orientation: 'horizontal'      
    lblTxtIn: 'default'
    theTxt: iAmTxt
    Label:
        text: root.lblTxtIn
    TextInput:
        id: iAmTxt  
        text: 'txt'        

<MyLayout@BoxLayout>:  
    orientation: 'vertical'

    LblTxt:   
        id: lt0
        lblTxtIn: 'LblTxtInput0'

    LblTxt:   
        id: lt1
        lblTxtIn: 'LblTxtInput1'

    LblTxt:   
        id: lt2
        lblTxtIn: 'LblTxtInput2'


    Button:
        text: 'print LblTxtInput [0, 1, 2]'
        on_release: print lt0.theTxt.text, lt1.theTxt.text, lt2.theTxt.text

MyLayout

Here's the Python code.

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
from kivy.core.window import Window

Window.size = (400,130)

from kivy.uix.boxlayout import BoxLayout

class LblTxt(BoxLayout):
    from kivy.properties import ObjectProperty
    theTxt = ObjectProperty(None)

class MyApp(App):

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

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

Here's a run screenshot. It will print a b c to the command line when the 'print LblTxtInput [0, 1, 2]' button is released.

enter image description here

I hope this helps you out.

Upvotes: 8

Related Questions