Change language

Python | TextInput in kiws using .kv file

| |

Kivy — it is a platform independent GUI tool in Python. Since it can run on Android, IOS, Linux, Windows, etc. It is mainly used to develop Android application, but that does not mean that it cannot be used in desktop applications.

Text Input:

The TextInput widget provides a field for editing plain text. Unicode, Multiline, cursor navigation, selection and clipboard functions are supported.

TextInput uses two different coordinate systems:

  • (x, y) — coordinates in pixels, mostly used for on-screen rendering.
  • (row, column) — cursor pointer in characters / lines used to highlight and move the cursor.
  Basic Approach:  1) import kivy 2) import kivyApp 3) import widger 4) import Relativelayout 5) import textinput 6) Set minimum version (optional) 7) Create Widget class 8) Create App class 9) create .kv file (name same as the app class): 1) create textinput 10) return Layout / widget / Class (according to requirement) 11) Run an instance of the class 

Implementation of the approach

# file

# Program to show how to use textinput
# (UX widget) in kiw using kv file

# import nodded module

import kivy 

# Your application base class inherits from the application class.
# app: always refers to your application instance

from import App 

# this limits the kivy version ie
# below this version you cannot
# use application or software

kivy.require ( ’1.9.0’ )

# Widgets are elements
# cat These are part of the user experience.

from kivy.uix.widget import Widget

# TextInput widget provides
# field for editing plain text

from kivy.uix.textinput import TextInput

# This layout allows you to set relative coordinates for children.

from kivy.uix.relativelayout import RelativeLayout

# Create widget class

class textinp (Widget):


# Create an application class

class MainApp (App):


# Constructing text input

def build ( self ):

  return textinp ()


# The organization of what you write will be shown to you

  # inactive

  def process ( self ):

text = self . root.ids. input . text

print (text)

# Run the application

if __ name__ = = " __ main__ " :

  MainApp (). Run ()


# main.kv file

# .kv code implementation file

"textinp & gt ;:

  title: ’ InputDialog’

auto_dismiss: False

  id : test1


# Use relative layout to position correctly


  orientation: ’ vertical’

pos: self . pos

size: root.size

  id : test2


# .kv text input detection

# And looking at this. pos and features


id : input

hint_text: ’Enter text’

pos_hint: { ’center_x’ : 0.5 , ’center_y’ : 0.705 }

size_hint: 0.95 , 0.5

on_text: app.process ( )

Exit :

When you run the application, you will see:

After some input you will see:


Learn programming in R: courses


Best Python online courses for 2022


Best laptop for Fortnite


Best laptop for Excel


Best laptop for Solidworks


Best laptop for Roblox


Best computer for crypto mining


Best laptop for Sims 4


Latest questions


psycopg2: insert multiple rows with one query

12 answers


How to convert Nonetype to int or string?

12 answers


How to specify multiple return types using type-hints

12 answers


Javascript Error: IPython is not defined in JupyterLab

12 answers



Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method