How To Define Custom Fonts - Python Tkinter GUI Tutorial #151 - YouTube

Channel: unknown

[0]
what's going on guys john elder here
[1]
from cody.com and in this video i'm
[3]
going to show you how to create custom
[4]
fonts with kinter and python
[13]
all right guys like i said in this video
[14]
we're going to look at defining custom
[16]
fonts
[16]
but before we get started if you like
[18]
this video you want to see more like it
[19]
be sure to smash the like button below
[20]
and subscribe to the channel give me a
[21]
thumbs up for the youtube algorithm
[23]
and check out codename.com we have
[24]
dozens of courses with hundreds of
[25]
videos that teach you to code
[26]
use coupon code youtube wanted to get 30
[28]
membership memberships all my courses
[29]
videos and books
[30]
for one time via just 49 which is
[32]
insanely cheap okay so i've got
[35]
a little app here and you can see i've
[37]
got three buttons and they all have
[38]
different fonts small font medium font
[40]
and big font and this one has a cross
[42]
through it and an underline
[43]
and it's italics and all kinds of things
[45]
now we've changed
[46]
fonts for buttons and labels and things
[48]
in the past that's not what i'm talking
[50]
about in this video in this video i'm
[51]
talking about defining an
[53]
actual font that we can then apply to
[56]
any button or
[56]
label or widget any way we want and it's
[59]
a little bit different it's a little
[60]
interesting and
[61]
it can make your life a lot easier
[62]
especially if you're changing all the
[64]
fonts of all your things and you want to
[66]
define it just one time
[68]
and then use it on everything else so
[69]
that's what we're going to look at in
[70]
this video so i've got a file called
[72]
fonts.pie it's our basic kinder starter
[73]
code that we always use i'm using the
[75]
sublime text editor and the git bash
[77]
terminal as always
[78]
so to do this we need to import font
[80]
which is a kenter thing that we can use
[83]
so let's go from and let's go
[85]
tkenter.font
[87]
we want to import capital font all right
[90]
so now we can use the font library or
[94]
whatever
[94]
to sort of define our own fonts we can't
[97]
like create a font
[98]
we're not like using photoshop to like
[101]
craft
[101]
certain fonts but we can define fonts
[104]
that already exist
[105]
and their attributes and use them
[107]
throughout our program so what we
[108]
all we need to do is let's just define
[110]
this thing and i'm going to start out by
[112]
calling it big font we want a big font
[114]
and now
[115]
this is going to equal a font all right
[117]
which is this thing that we just
[119]
imported is basically a widget now right
[122]
and now
[123]
we can set all the things that we want
[124]
so we can set the family the font family
[127]
and you know i always use helvetica so
[129]
i'll just put helvetica in there
[131]
right and then we can set the size
[134]
so this is a big font so i'm going to
[136]
set it at 42 really big
[138]
you know this goes from zero to you know
[140]
as much as high as you want
[142]
basically uh your basic basic text is
[145]
usually 12
[146]
ish you know 12 14 10 somewhere around
[149]
there
[150]
so that's sort of your starting point
[151]
with size so
[153]
size 42 pretty big now we can set the
[156]
weight of this if we want
[157]
so i'm going to set this to bold so you
[159]
can do bold
[161]
or you can do normal if you want normal
[164]
you can just leave
[165]
off weight but i'm going to make this
[167]
bold so let's put this as bold
[169]
now we can also do slant if we want
[173]
so we can do italic this will make it
[176]
italic slanted
[177]
or we can do roman which is regular
[179]
straight up and down so i'll leave this
[181]
at roman
[182]
again if you just want it to be the
[183]
normal default you don't have to put a
[184]
slant on there and set it equal to roman
[186]
but you can
[187]
so we'll just go ahead and do that uh we
[189]
can have an underline
[191]
so this is either a one to have an
[193]
underlined or a zero to not have an
[195]
underline so
[196]
i'll leave that off for now and you can
[198]
we can also have an over
[199]
strike we can set that to one to have it
[203]
strike through
[204]
or zero to not have a strike at all and
[207]
really that's all there is to it so now
[209]
so let's
[210]
comment here to find our font
[215]
okay and now we can come down here and
[217]
let's define a button
[219]
and i'm going to call this my underscore
[221]
button one and this is a button
[224]
we want to put it in root we want the
[225]
text to equal
[227]
let's say big text and now we also have
[230]
to set the font
[231]
now normally when i set the font for
[233]
something i do
[234]
like you know helvetica well that's not
[237]
spelled right but you get the idea this
[239]
is how i usually set the font
[240]
well instead of putting all of this
[242]
stuff in here
[244]
from now on whenever we want to use this
[246]
font we just call
[248]
big font whatever we called it right so
[251]
big font and that's all there is to it
[253]
so now let's uh my underscore button
[256]
dot pack and give this a pad y of like
[258]
20 to push it down screen a little bit
[259]
so we can save this and let's run it so
[261]
let's go python fonts dot pi
[264]
and when we do we get this big
[267]
text text it's bold it's helvetica
[271]
and it's very cool we can set you know
[272]
we can change this if we want say if we
[274]
want
[275]
times right we can save this and run it
[279]
and you can see now the text is slightly
[281]
different it's not helvetica anymore
[283]
it's
[284]
kind of got brackety things on the t
[287]
you know and it's uh you know it's just
[289]
a little bit different so
[290]
that's really all there is to it now we
[293]
can use this
[294]
big fawn anytime we want so if we came
[297]
down here and
[298]
uh and made a label so let's go my
[301]
underscore label
[303]
and that's a label we want to put it in
[305]
root we want the text to equal
[308]
more big text
[312]
and we can set the font equal to big
[313]
font and again we can my underscore
[315]
label dot pack
[317]
give this a pad y of like 20 push down
[319]
screen a little bit same deal we could
[320]
save this and run it
[322]
and down here now we have this text is
[325]
in that same size right
[326]
it's big it's bold it's uh it's a times
[330]
font and it's very cool so you know we
[333]
can play around with this
[334]
if we want to see for instance uh what a
[338]
different thing
[339]
what what these different options are so
[342]
we can come down here and let's make
[343]
this one
[344]
um medium font
[347]
right and so let's change this to
[350]
helvetica
[352]
i'll that take out there we go and maybe
[354]
we'll put this at 24
[356]
maybe we want this to be normal
[357]
[Music]
[359]
instead of roman let's put this at
[361]
italic
[365]
right i always want to put italics
[368]
because that's how i say it italics
[369]
but it's italic right and if we wanted
[372]
underline
[373]
maybe we could do that and so let's come
[376]
down here
[376]
and well instead of maybe let's just
[379]
copy
[380]
this guy instead of making this label
[383]
big font maybe we'll change that to
[384]
medium font right so
[386]
save this and run it
[390]
you can see this is different
[393]
font face this is helvetica as opposed
[395]
to times up here
[397]
it's underlined it's kind of slanted a
[399]
little it's smaller text
[401]
it's not bold right very cool and it's
[403]
just that easy now anytime you want to
[405]
use those things those fonts you could
[407]
just call them by calling their name
[408]
and slapping them in the font section of
[411]
your widget where you define the widget
[413]
and you're good to go
[414]
so this may seem like a very simple
[416]
thing but it's very useful especially if
[418]
you have an app with lots of buttons or
[419]
lots of text and you want that text
[422]
to have the same cohesive font style
[425]
throughout your app and you don't want
[427]
to define it on every single one
[429]
because maybe later on you want to
[430]
change the font so if you've defined all
[432]
of your text
[433]
or in all of your buttons and all of
[435]
your things to have
[437]
big font font and you want to change big
[439]
font
[440]
to slightly smaller you can change it in
[442]
one place
[443]
right we could just come up here where
[445]
we define this thing and if we wanted to
[447]
you know if the boss said is big too big
[450]
we we need to put it at 40 from now on
[452]
you could just change that right there
[453]
and it will update on all of your
[455]
widgets all of your buttons all your
[456]
labels all of your everything
[458]
throughout your app and just much easier
[460]
to do it that way
[461]
and uh pretty cool so that's all for
[463]
this video if you liked it be sure to
[464]
smash the like button below subscribe to
[466]
that channel give me a thumbs up for the
[467]
youtube algorithm and check out
[468]
codemy.com you can use coupon code
[470]
youtube1 to get 30
[471]
memberships to pages 49. taxes all my
[474]
courses
[474]
over 47 courses hundreds of videos and
[476]
the pds of all my best-selling coding
[478]
books
[478]
join over a hundred thousand students
[480]
learning to code just like you my name
[481]
is john elder from codename.com and i'll
[483]
see in the next video