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

# main.py 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 kivy.app 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
# GUI
# 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):

  pass

 
# 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

  RelativeLayout:

  orientation: ’ vertical’

pos: self . pos

size: root.size

  id : test2

 

# .kv text input detection

# And looking at this. pos and features

TextInput:

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:

Shop

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

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically