Python Tkinter: How to create a Button in Tkinter
Jun 20, 2025
Tkinter is Python's most popular Graphical User Interface (GUI) library. This topic explains the proper use of this library and its resources. Python Tkinter: How to create a Button in Tkinter Support the Channel šš: Buy me a coffee ā : https://buymeacoffee.com/usandopy_ ā”ļø Connect with me on: Instagram: https://www.instagram.com/pybeginners/ Twitter: https://x.com/joaofuti_ LinkedIn: https://www.linkedin.com/in/joao-futi-muanda-16b980175/ Website: https://www.usandopy.com/en Thread: https://www.threads.net/@pybeginners
View Video Transcript
0:00
hello guys welcome back to the channel
0:01
my name is so today we are going to
0:03
learn how we can create Bon iner okay in
0:07
order to create botton in okay so this
0:09
is the syntax that we can follow to
0:11
create a botton okay as always so a
0:13
bottom it comes inside the class bottom
0:15
okay so the bottom is this one as we can
0:17
see and this is a label so this is a
0:21
syntax that we can create a label so in
0:22
this video we are going to perform
0:24
operation like how to create a botm in
0:26
okay we'll show the botm inside the
0:28
window as that is showing here okay so
0:30
we'll set the properties of a bom we can
0:32
change the color we can change the test
0:34
the size of a botom okay and we also
0:37
going to have an event by using botom
0:40
iner okay so for that as always let's go
0:43
to our test editor okay test editor boom
0:46
I am here so this is the previous one
0:49
okay so let's just going to delete
0:51
everything okay now I'm going I'm going
0:53
to need this guy okay I need this guy
0:57
come here I can just use the here boom
1:01
okay you stay and remaining bye-bye boom
1:05
I don't need you guys and you bye-bye
1:09
you bye-bye you guys can stay inside of
1:11
the window
1:13
okay
1:15
boom okay those are labels okay those
1:19
are labels and this label doesn't matter
1:22
too much okay I can just save and if I
1:23
run this nothing that I just have one
1:25
label here which is saying name okay
1:29
don't worry about this so how we can
1:30
create a botm in so in order to create a
1:33
BM in so we have to do something like
1:36
that okay let me see I'm going to create
1:38
one variable first okay so let's say bom
1:41
one okay uh B1 we canest we can B1 equal
1:45
okay so it comes inside of the class
1:47
botom this one open and close Okay so
1:50
after that we have to show our Bon
1:52
inside the window okay so for that let's
1:54
call Window okay comma okay then let's
1:58
say test okay so the test is the will be
2:00
the name of the bottom so for that we
2:02
let's say we say something like click
2:05
click here save if I save and if I run
2:09
nothing's going is going to happen
2:11
nothing's going to show okay so in order
2:13
to show the bottom we have to do
2:15
something like this okay let's say B1
2:17
okay do okay uh let's use grid since we
2:21
are using grid here okay I'm I can just
2:23
copy this guy and place here okay delete
2:27
and copy grid okay
2:31
you come here and
2:34
stay so uh okay so after that let me
2:39
learn this to see how how is the my big
2:41
mess so we can see the buttons here okay
2:43
but uh I didn't like it because they're
2:45
on top of each other okay so this guy
2:47
stay row zero this stay in row zero but
2:49
this guy come on column one okay column
2:52
one if I save this and I
2:54
run and boom now we have the name and
2:58
the click here okay
3:01
so uh okay let's say just uh okay yeah
3:06
let's keep here M name itself okay uh no
3:09
name now let's say first botom
3:12
first botom first botom okay I save and
3:17
okay let's give some size maybe uh
3:20
font uh font because this test is too
3:24
small font AR get font
3:30
font would be equal I open and close
3:33
let's say
3:35
Arial Arial okay okay Arial bold at
3:40
least and comma here let's say at least
3:44
12 if I save in if I run boom okay now
3:47
we have a first bom okay and Pad y for
3:51
this guy let's give maybe blah blah
3:54
let's say 10 save and if I run okay now
3:57
it's a little down okay now we have our
3:59
botom okay perfect so this is how we can
4:03
create a botm in Python okay so this is
4:05
our label and this is our Boton okay so
4:07
we use this
4:09
class and this the test will be the name
4:12
of the botton and if I keep it if I
4:14
didn't by default it is raised okay
4:18
so so we can change also the color of
4:21
this bottom okay as we can see here uh
4:24
is not good at all so to change the
4:26
color of a button we can just come here
4:28
okay give a little space and we can say
4:30
something like that okay for BJ uh BJ we
4:33
know is for background okay let's say
4:36
blue blue save and if I run boom now our
4:40
button is blue and to change the color
4:43
of the test of a Buton we can say FG FG
4:46
equal we can say white something like
4:49
this okay FG never forget to separate
4:52
the things okay by Saving if I run boom
4:55
now we have it okay we have everything
4:58
so uh uh the Buton I think we can change
5:02
also the font size let me see let's just
5:04
copy this guy copy and if I put it comma
5:08
if I paste save uh I don't remember if I
5:11
can save yeah okay we can change also
5:13
the font size of a bottom as we can see
5:15
okay are bold 12 and it also increases
5:19
okay so this is how we can change
5:22
everything okay the color and the fonts
5:24
uh background and apart of this okay we
5:27
can change also something which is very
5:29
important which is the size of a bot
5:31
okay so to change the size of a bon we
5:33
can just change the width of a bottm
5:36
itself for WID okay width equal uh let's
5:40
say blah blah at least 12 comma then
5:44
let's say height height we can say at
5:47
least two comma and if I save and if I
5:49
run this boom as now we can say we have
5:51
a big bottom here okay so this is how we
5:54
can change a size of a button just by
5:56
change the width and the height of this
5:59
same botom then we boom change the size
6:03
of a botom okay so apart of this there
6:07
is something really really important
6:09
when it comes to botom okay which is
6:11
events click event okay when we click on
6:14
botton we want it to perform something
6:16
okay so this is something really very
6:17
important so now let's learn how we can
6:20
use that click event in the boot okay
6:22
for that let me can put this guy a
6:25
little up because we might need it okay
6:27
so to use a click event in a but we have
6:30
to do something like that okay so here
6:32
on the top okay below the window I'm
6:34
going to create one function def okay so
6:38
this function will be uh will be called
6:40
hello okay hello just to say hi I do
6:43
this then dot come here so we want that
6:48
every time when we click this bottom the
6:50
bottom okay this function hello must do
6:52
something okay must to perform something
6:54
so in order for that we can just say
6:56
okay let's print print it will say
7:00
uh let's print what okay let's
7:03
print
7:05
okay don't like this okay so if I save
7:09
this and if I run if I click in this
7:12
button boom nothing will happen so in
7:15
order to make this function to print
7:17
high we have to connect the we have to
7:19
connect the function and the bottom so
7:21
for that we have to do something like
7:23
this okay I can just come here okay I
7:25
will come here okay in order to connect
7:27
the function with a bottom we can do
7:28
something like that okay okay we can
7:29
call another attribute which is called
7:33
uh command Okay command so after that
7:36
command we have to say equal okay
7:38
command must be equal the name of the
7:40
function itself that we want to use okay
7:42
I can do something that hello okay see
7:45
here we don't use open and close okay
7:47
just like this hello and comma so this
7:50
means this function this guy it's this
7:53
one okay every time when we click here
7:54
this function will be executed okay so
7:56
for that let me come here up and let me
7:59
save in if I execute
8:00
this check this if I click here the
8:04
function will be executed say hi
8:07
okay so but now we want that every time
8:10
we click here this High come here okay
8:13
must show here in the our label okay so
8:15
for that we can do something like this
8:17
see uh instead of printing hual we can
8:20
say something like this okay we can get
8:23
this label okay this lbl okay dot we can
8:28
just change the attribute okay this
8:31
attribute which is test so for that we
8:33
can do something like that okay label do
8:36
configure okay configure label do
8:39
configure open and close Okay what we
8:42
want to change we want to change the
8:43
test this is guy so we can do something
8:45
like that test okay then will be equal
8:49
okay uh what we want to say okay we want
8:52
to say hi okay you come here and you
8:56
stay here save and if I run this this
9:00
let's see if I click boom it change High
9:03
and the print high now we we don't want
9:06
it to print high okay we just want it to
9:08
change it h okay so if you we don't want
9:10
it to print we can just comment this or
9:12
delete this line okay I save if I run
9:15
this boom now we have here if I click
9:18
boom High round is not printing anymore
9:20
okay so apart of changing this way you
9:22
can change also this way okay
9:24
for H you can say something okay label
9:28
the name of the label open and close
9:30
here you'll call the name of the
9:32
attribute that you want to change is
9:34
test do this okay uh single quote call
9:37
the the attribute test then you put just
9:40
equal equal what equal the thing that we
9:42
want to change okay uh let's
9:47
say hi something like that okay so if I
9:52
save this and if I run let's see if I
9:55
click it will be high it's like okay it
9:58
change first to this one High round then
10:00
it change again to this one high
10:02
something like that okay you see even if
10:04
I comment this boom you stay save and if
10:07
I run if I click it will be high so it's
10:10
just like two ways of doing the same
10:12
thing okay so you can use either this
10:14
way or either this way so this is how we
10:16
use click event in botoms
10:23
okay uh so
10:26
well so guys okay we'll stay here okay
10:29
uh on this tutorial so the next tutorial
10:32
we'll do something different I think
10:35
okay so if you like this video give a
10:36
like to this video uh this is subscribe
10:39
to the channel and see you in the next
10:41
video okay my name is and bye-bye