Text Inputs and Labels in Kivy, Python's Universal App Builder for iOS, Android, Linux, Mac, and PC!

LeMaster Tech
183 followers
90 Video Views·Apr 23, 2025
Learn to develop universally compatible apps using Python and Kivy!! This is episode 2 in an intro to Kivy series from LeMaster Tech. This episode covers creating code to use a Grid layout, text inputs, and labels in Kivy! This also shows the basics of using a password setting for a privacy text input box.
Be sure to check out our channel for tons of additional python tutorials and practice problems and be sure to like and subscribe if you find our content useful!!
https://www.youtube.com/channel/UCV5Ab39YnXvTZ6Grar9URxQ
If you want to see anything specific on the channel or have technical questions about anything leave a comment on our of our videos and we will get back as soon as we can!
Thanks for watching and supporting the channel!
hello welcome back to the channel uh
today's going to be episode 2 in our
introduction to kivy with python
tutorial series and if you missed the
first video um this is the code that we
are starting from because we built it in
the last video it's definitely something
you can get caught up to right now but
if you missed it kivi is essentially a
universal app building package that uses
python code to drive it and once you
have an app in kivy it works on mac pc
linux both android and apple
app stores so it's a really powerful
tool to build
apps that you can roll out in a variety
of places today we're going to get
started with actually putting some
some labels and uh text inputs on our
screen so last time we created this uh
we created this app that just opens a
window that says hello world and uh kind
of the nice feature of kivy we touched
on is it's it's rapidly resizable this
is how it works on so many platforms
so we played around with that a little
bit let's start building something a
little bit more useful let's make uh
what would be considered like a login
screen so a few more things we're going
to import for this video a few more user
interface
options we're going to grab a grid
layout and what that actually means
we'll get into as we
dive into the video and then we'll also
need
a text input so both of those are going
to come from the kivi.uix which means
user interface
package
and again the kivi standard is
for importing things is always going to
be kind of this like from and then
everything is lowercase and then once
you're importing it's usually going to
be first letter of each word is
uppercase that's just kind of uh the
kivi standard and once we get into
actually using the kv design language
which we will get into
that'll that'll become really
obvious too
so we're going to make another class and
we'll actually call this our login
screen and this will be where we build
out though everything
and then in here we're going to say we
want this to be a grid layout right so
a grid layout essentially is dividing
your screen up into a grid
with a certain number of rows and
columns and that's where it's going to
stick the different things that you
define
so that's just a brief introduction to
it but let's go ahead and actually build
something in it so we can see what that
means
so for making
you're probably familiar with pi if
you're familiar with python you're
probably familiar with the init function
when you create a class
but something we do for uh kibby is uh
def in it self and then we also pass in
these kw args these arguments
and because we're we're pulling in a
super
um
so
we're going to say login screen and self
okay
and some of this just uh
understand this is what you need to do
um you can dig into why if you really
want but essentially what we just
created here is what you're going to
create every time you make it a class
for another screen within kibi so it's
one of those things you follow along you
do it a few times and then you're
familiar with it and you won't have any
problems so those are going to be your
first couple lines pretty much always
and now we'll actually get into the
specific design stuff so self.calls
we're defining how many columns are in
our grid layout here and we'll go with
two right now because all we want is a
box that asks you for your username and
asks you for a password and then we'll
make a couple text inputs
so we're going to use this kibi self.add
widget function
to actually put a couple labels on the
screen
and so label text equals and then
username right
if you watched the last video you've
seen this label text equals format
before
but then if you're building a screen
separately that you plan on calling
later you have to use this add widget
functionality to stick it into a grid
so that's what we did here and then
let's call this self dot
username so what we did is we just stuck
a widget on the screen that's going to
say username and by default it's going
to start in the top left
that's kind of the grid layout format as
it goes left to right and then top to
bottom if you don't define a placement
for everything so we will eventually
touch on defining a placement but for
now we're just going to get a login
screen going
so we'll say self.username equals and
this is going to be a new one text input
that's what we
brought in for this video and then we'll
say multiline equals false and that's
the only parameter we'll give it for now
but this is saying that right next to
the actual username
box there's going to be a text input
where you enter data you enter your
username and you're not going to be able
to go to the next level so that'll kind
of limit total characters
but that's probably the most common sort
of username entry field that you've seen
as it's just one line of text anyways
um
and then we're going to use that add
widget function again self.add widget
and we're going to tell them
username
and i think i spelled that right
okay and this this is pretty cool uh if
actually what we have to do as well
inside of our app rather than returning
this label now we are just going to call
login screen
so now before we were saying okay here's
my master app
all i want to do is stick a label saying
hello world in the middle of it now i
want to take the whole app and i want to
stuff the login screen inside of it so
we should be able to see user name on
the screen if we run it real quick
uh grid layout is not defined well i
disagree
class
oh it's because i didn't capitalize the
l
after all that talk about
syntax
there we go
well
i thought it was because i didn't
capitalize theo
username is not defined
that's because it's self.username
awesome
say little syntax checks when you're
trying to go fast they uh they never
work
so let's go ahead and say uh look at
that so we made the username label and
we
are trying to make it a long username
but if i hit enter it doesn't let me go
down to the next line i can type really
long and it'll scroll over but there's
no multi-line
um
so that's pretty cool but really what we
want is username and password so i'm
going to grab all three of these lines
we just made and i'm going to modify
these ones to be for the password
and there's actually something pretty
cool that we're going to do
which is we're actually going to make it
so that when you type in a password the
um program is storing the text that
you're entering but it's using those
asterisks um on screen so that right
it's kind of a privacy feature that you
probably used to any time you've seen a
password it's very normal for logging
screens to do this and in kibi it's
actually a setting called password and
so we're going to say password is true
and multi-line is false
and we don't have to do anything down to
uh our our class for the app or the run
logic
um we just stuffed a little bit of extra
in here
and then if we go ahead and run this we
now see we get username and password and
we'll say pp is a cool username and if i
type in the password uh you know i'm
typing in secret password right now but
there's no way you guys could know that
because we set that password um
parameter true so right there that's
kind of cool under 10 minutes and we
built a functioning login page for an
app um so uh hopefully you found that
useful uh
if you have any questions or want to
make sure something gets covered in this
series feel free to let me know about in
the comments otherwise if you found this
or anything else on the channel useful i
really appreciate a liking to subscribe
and as always good luck with your code
and thanks so much for watching the
channel thanks bye
