Flet provides various ways to display and style text in your applications. The Text widget is the primary way to display static text content. In this guide, we'll explore how to use and customize text in Flet.
Python Flet - Working with Text in Flet
Article: https://www.usandopy.com/en/artigo/working-with-text-in-flet/
💖 Donate and help us create more amazing content!
🙌 Every contribution makes a difference!
☕ Buy me a coffee: https://buymeacoffee.com/usandopython
💖Support this channel
https://www.youtube.com/channel/UCpL2Gru508Z39oPqu1FIg4Q/join
⚡️ Connect with me on:
🌐 Website: https://www.usandopy.com/en/
📸 Instagram: https://www.instagram.com/pybeginners/
🐦 Twitter: https://x.com/joaofuti_
📢 Threads: https://www.threads.net/@pybeginners
🔗 LinkedIn: https://www.linkedin.com/in/joao-futi-muanda-16b980175/
🎥 YouTube: https://www.youtube.com/ @pybeginners
Show More Show Less View Video Transcript
0:00
hello guys welcome back to the channel
0:03
here so today we are going to learn how
0:05
we can work with test in Python flat
0:08
okay so flat provide various ways to
0:11
display and style a test in your
0:13
application so the test there is a test
0:15
we we get okay so this test we okay is
0:18
the primary way to display any static
0:21
test content that you have okay inside
0:22
of your app so here in this tutorial we
0:26
are going to explore how we can use it
0:28
and how we can customize it this test
0:30
widget in flat so the first thing that
0:33
we can do is the base basic usage of the
0:37
test okay so for that let's do something
0:39
like this okay so in
0:41
order for us
0:44
to work with test okay we get we have to
0:47
do something like this okay i'm going to
0:48
create one variable called uh test okay
0:52
now I just I'm going to call it as a t
0:53
itself okay t uh this T will be equal
0:57
for them in order to work with the test
0:59
widget get we have to do something like
1:00
this ft dot text okay this way and open
1:05
and close so this test one is the widget
1:07
get that help us to show test in in our
1:11
app so here inside we can give anything
1:14
that we want for examp let's say
1:15
something like this hello hello flat
1:18
hello flat and if I save this okay if I
1:21
run nothing is going to happen okay as
1:24
always when we work with flet we need to
1:27
update our page so that it can reflects
1:29
the change that we we will do in our app
1:32
okay so for that after this in order for
1:36
me to show this test we get inside of
1:38
our main app we have to do something
1:40
like this okay for
1:47
examp it it update itself okay directly
1:50
so after this I just say I can just give
1:52
this t here inside okay update what t
1:55
save and I'm going to run this and boom
1:59
as you can see now we have this guy here
2:02
h flat oh my god what I wrote sorry it's
2:06
supposed to be hello okay hello flat
2:08
save and let me run
2:10
again boom as you can see okay now we
2:13
have here hello flat okay this this is
2:15
the way that we can show any test inside
2:19
of of our app so apart of this this okay
2:22
we can also customize this test
2:25
properties like the size of the test
2:28
even the color the weight the alignment
2:31
and more a lot of stuff that we can do
2:33
with the test widget get okay widget so
2:36
for that let's do something like this
2:37
okay instead of this same test widget
2:40
let's do something like this okay uh
2:42
let's keep hello widget okay so in order
2:44
for us to styize this thing we can do
2:46
something like this for I can give
2:48
something like size okay uh I think it
2:50
will be better if I keep doing it this
2:52
everything like down uh okay let's let
2:55
me do something like this
2:57
okay okay i'll start from here okay for
2:59
them this guy come down will be better
3:02
this way okay size so for size I can
3:04
define the font size okay comma when you
3:08
do this for the size equal 24 you need
3:10
to put comma here i'm going to save and
3:13
I'm going to run it and I got error i
3:16
got error because I need to separate
3:18
this test with the size so I just need
3:20
to put comma here so I think will be
3:23
better if I keep this guy also down this
3:25
way will be better okay so that I can
3:26
see what I'm doing so now just let me
3:30
put it a little front yeah I think from
3:33
here I can control it better perfect so
3:35
now I'm going to save and I'm going to
3:39
run now as you can see the size increase
3:42
it okay so apart of that we can change
3:44
the colors the test so for that we just
3:47
need to do something like this color
3:50
equal here we can give any color that we
3:52
want for if I give blue save and let me
3:55
put comma here save and if I
3:57
run boom as you can see now the color is
4:00
blue okay and apart of that I can give
4:02
also extra decimal colors for same like
4:04
this cardinal and let me give any number
4:07
which I don't have any number in my head
4:09
but I'm just going to give random number
4:11
two three 1 2 3 1 2 3 it's supposed to
4:14
be six safe and if I run this as you can
4:17
see now the test is black uh black color
4:21
so uh apart of that we can give also the
4:24
weight uh let me give weight
4:28
okay the weight of the test uh for But
4:31
uh I can give like a bl bold which is uh
4:35
neg bold even uh which one more bold
4:39
normal okay so for bold I can do
4:41
something like this fd dot font this way
4:45
okay
4:46
font wage okay font weight dot here I
4:51
can give any font which which I want for
4:53
example there is bold this way okay
4:55
capital B save and if I run
4:58
this boom as you can see now the font is
5:01
bold okay so for normal we don't need to
5:04
give it okay we just we can just keep it
5:06
like that itself okay and apart of that
5:09
I can give like italic also
5:12
italic for italic I just need to turn it
5:16
on okay by default it is fails but if
5:19
you want to turn it on we just need to
5:21
give it like something like this true
5:24
comma save and if I run this guy boom as
5:27
you can see now it is itallic okay and
5:31
we can also align the test for them
5:33
something like this okay uh text
5:37
underscore alignment text alignment
5:40
align text align will be equal FD
5:45
dot
5:47
text align text align text align this
5:52
way dot and from here I can decide okay
5:55
for I can give center something like
5:57
this comma and if I save this now let me
6:01
run this guy I run as you uh now the
6:04
test will be center okay since there is
6:06
nothing so that's why it's showing here
6:09
I think nothing will show because since
6:11
there is only one thing itself and it's
6:13
just keeping randomly if I give uh at
6:15
least
6:17
left Ctrl P oh left I think is the
6:20
default one nothing will change here for
6:21
sure exactly Okay um at least if I give
6:24
right save and
6:26
run yeah nothing will show but if it
6:29
will be inside of one uh h there is
6:31
another thing that okay which is called
6:33
container so that will make effectable
6:35
like this it will not show properly so
6:39
guys this is how you can work with test
6:41
in Python fret okay so if you want to
6:43
see this okay I will keep a link in
6:45
description of this video there is a
6:46
tutorial that you can follow and you can
6:48
see more example about how you can use
6:51
tests inside of your flat app so guys I
6:55
am Jo so welcome to the channel and see
6:57
you in the next video bye

