Kivy is a platform-independent GUI tool in Python. As it can be run on Android, IOS, linux and Windows etc. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktops applications.
In this article we will learn how we can add a button with the Text input in kivy, just like the same we have in the input and submit button. Before proceeding to that you must know about Textinput widget and Button in kivy.
TextInput: The TextInput widget provides a box for editable plain text. Unicode, multiline, cursor navigation, selection and clipboard features are supported.
Button: The Button is a Label with associated actions that are triggered when the button is pressed (or released after a click/touch). We can add functions behind the button and style the button.
To work with Textinput and buttons you have to import it by the command –
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
Basic Approach:
1) import kivy
2) import kivyApp
3) import Button
4) import Boxlayout
5) import Textinput
6) import BoxLayout
7) Set minimum version(optional)
8) create App class
9) return Layout/widget/Class(according to requirement)
10) Run an instance of the class
Kivy Tutorial – Learn Kivy with Examples.
Implementation of the Approach –
main.py file
import kivy
from kivy.app import App
kivy.require( '1.9.1' )
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout
from kivy.config import Config
Config. set ( 'graphics' , 'resizable' , True )
class BTNTEXTApp(App):
def build( self ):
b = BoxLayout(orientation = 'vertical' , )
t = TextInput(font_size = 30 ,
size_hint_y = None ,
height = 100 )
f = Button(text = "Push Me !" ,
font_size = "20sp" ,
background_color = (. 67 , 1 , . 33 , 1 ),
color = ( 1 , 1 , 1 , 1 ) )
b.add_widget(t)
b.add_widget(f)
return b
if __name__ = = "__main__" :
BTNTEXTApp().run()
|
Output:


Last Updated :
28 Feb, 2020
Like Article
Save Article
Vote for difficulty
Current difficulty :
Basic