Field noteEN1 min read
Kivy Course #6 – Text Input and Input Handling
Archive note: This article is preserved in its original form. Versions, links or commands may now be outdated.
At the sixth part of the course, we are talking about text input and handling the text in text input box. To make a input chance to the user, TextInput class can be used. Here, a login system is made by making username and password check and afterwards, print the result to the console.
Python file
#-*-coding:utf-8-*-
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.properties import NumericProperty
from kivy.clock import Clock
class RootWidget(GridLayout):
def validateUser(self):
if self.ids.username.text == 'masti' and \
self.ids.sifre.text == 'strong':
print "Iyi giris"
else:
print 'hatali bilgi'
class kullaniciApp(App):
def build(self):
return RootWidget()
if __name__ == "__main__":
App = kullaniciApp()
App.run()
Kivy file
<RootWidget>:
rows: 2
cols: 2
Label:
text: "User name"
TextInput:
id: username
multiline: False
Label:
text: "Password"
TextInput:
id: sifre
password: True
multiline: False
on_text_validate: root.validateUser()