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: Geometry managers 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
Show More Show Less View Video Transcript
0:00
hello guys welcome back to the channel
0:01
My name is Ja So today we are going to
0:03
learn about geometry managers in tinter
0:05
Okay so as I said before in the previous
0:08
video okay so in the we have a ways that
0:11
we that help us to place the wedgates
0:14
inside a window in the okay So you uh
0:17
practically there are three ways to do
0:19
that Okay as we can see on this example
0:21
Okay so just by looking like this
0:23
there's a little mess Okay but don't
0:25
worry about that So if I I come in front
0:27
Okay the first way is by using place
0:29
Okay so place if you use place if you
0:32
want to organize your wickets inside the
0:35
window by using place is like okay So
0:38
place it give you freedom for you to
0:40
move those wets wherever you want inside
0:44
the window Okay so you are free to move
0:46
you can come here in the X in the Y So
0:49
wherever you want to place those wets
0:52
you are free by using place Okay so this
0:54
is the syntax Okay so the syntax is like
0:56
okay So you'll be having the wicket
0:58
maybe the name of of the thing So then
0:59
you'll put dot place and here inside
1:02
okay you'll give some options that works
1:04
with place So let's show this example of
1:06
this So it's something like this Okay So
1:09
if I come here for example this those
1:10
previous examples that we used So I'm
1:13
just going to remove all those stuffs
1:14
Okay let me remove I'll be using place
1:17
here So let's say label one level two
1:19
level three dot place I will open and
1:22
close Okay So I'll come inside So when
1:25
we use place we use something uh like x
1:29
and y Okay So x it moving horizontal and
1:33
y it moving vertical Okay So for examp
1:35
if we use the place let's say I want to
1:37
place this thing Okay This wicate and x
1:40
equal for example five Okay Comma then
1:44
and y
1:46
equal and we can say at least 100 Okay
1:49
No 100 is too much Okay So we can say 10
1:52
So if I save this and if I run we can
1:54
see everything is on top of order Why
1:57
Because we put we place everything on
1:58
the same place But we can change this as
2:01
we said Okay So by using place you can
2:03
move the widgets wherever you want
2:05
inside the window Okay For instance if I
2:07
give like this uh for this one keep 10
2:10
and I'm just going to move vertical Okay
2:13
Because as we said y is moving vertical
2:16
and x is moving horizontal Okay So let's
2:19
move this one a little down Let's move
2:20
it down 100 And this one let's move also
2:23
down for them Uh 200 might be enough if
2:28
I save this And if I run as we can say
2:32
okay we move this ones Okay Uh we move
2:36
this one the blue one okay down for 200
2:39
where y is 200 and this one okay where
2:42
red one where y is equal 100 Okay for
2:46
now let's uh let's keep it like for
2:48
example here as we have in now in now
2:50
our example Okay so for that I just can
2:52
do something like this Okay if I look
2:54
properly let me see and it's like this
2:57
one it move a little bit for
3:00
100 here No I think it's 200 maybe
3:05
200 and this guy also it move a little
3:08
bit If I check on where is it Uh
3:13
okay Perfect So I just have to move it a
3:17
little
3:18
bit 200 This guy might be 150 And this
3:24
can
3:25
be 30 Okay If I save and if I run this
3:28
now as we can see okay we move it Okay
3:31
So by using place you are free to move
3:33
the widget wherever you want Okay You
3:35
are free to do as you wish to do it Okay
3:39
So this is by using place manager So uh
3:42
now apart of place okay there is another
3:43
one
3:44
also which is this guy Okay that is
3:49
packed So uh this geometry manager okay
3:52
it organize the widgets into blocks
3:55
before placing them Okay so it keep
3:56
organizing things like this Okay before
3:58
you give any any options for that okay
4:01
so this is the syntax for that Okay so
4:03
the name of the widget.pack and here
4:05
inside you put some options for that So
4:08
now let's see some example as I said
4:10
Okay let's come here for by using pack
4:13
is all we can do something like that
4:14
Okay let's change this Come here and
4:17
come here also If I delete this uh I
4:20
think won't be enough Okay blah blah
4:22
blah blah blah Okay stop there and you
4:26
and you one two then the U also So while
4:30
using pack we have to do something like
4:31
that Okay for examp this is how to write
4:34
and open and close So here inside we
4:36
have to give some options Okay for uh if
4:39
I give if I give just like that Okay if
4:41
I save and if I run no as we said it
4:44
organize things as a block Okay so the
4:47
first one comes will be on the top the
4:50
second one be in the middle and you just
4:51
keep adding like that Okay like down
4:53
down down down down so we can give also
4:56
some option for that Okay So for that
4:58
let's say something like that for if I
4:59
keep some option for them this one I can
5:01
say for them something like side equal I
5:05
can say like top okay this way if I save
5:08
and I run so is already in the top so
5:10
that's why nothing change and if I come
5:12
for example on this one okay if I said
5:15
side okay oh I mistake everything must
5:17
be in the small letter okay if I say
5:21
side equal and I can say for Right Okay
5:26
Right Right I think this is how to write
5:28
Right If I save this and if I run Oh Oh
5:31
wrong Uh this is right Is wrong This is
5:34
not uh Do you mean right Yeah This is
5:36
the right way to write to right Oh it's
5:38
complicated The right
5:41
right Okay This is the right right Okay
5:44
Wow I like this song The right right
5:47
Okay This is the right right Okay So I
5:49
save and if I run this as we can say no
5:52
we said right So he come he came here in
5:54
the right this guy Okay this red
5:57
one and apart of right okay we have also
6:01
we can say for example something like
6:02
also side okay equal left Okay if I save
6:08
this and if I run now we can see this
6:10
blue one came on left Okay so we can set
6:13
something like also uh let me copy this
6:15
guy Copy come down and boom Uh this guy
6:20
will be level four
6:23
I save and if I if I say bottom so there
6:26
is also bottom okay b okay b save and if
6:31
I run this now we can say this guy is on
6:34
bottom okay so but let me change the
6:36
color for them to
6:38
uh purple now say I don't know if this
6:42
is the correct way if I save yeah okay
6:44
purple yeah this as we can uh this guy
6:47
now is on the bottom okay so to be
6:50
honest for me I don't like to use uh
6:54
pack too much because to be honest I
6:56
don't know how it work how it works
6:59
properly okay it's like a big mess to be
7:01
honest I use more grid in combination
7:03
with place that I think is something
7:05
more easy okay so what is grid so let me
7:07
show what is grid so grid is this guy
7:09
okay the next one so grid it works like
7:12
excel sheet okay so we have a columns
7:15
which are those guys okay then we have
7:17
rows okay which are for this is row zero
7:20
these ones row one come here row two
7:23
come this row three and so on So column
7:26
are those ones okay like this blah blah
7:28
blah So how to give how to use grid So
7:32
when we are using grid you have to give
7:34
two attributes which is row and column
7:37
Okay So this is the syntax Okay Uh the
7:40
name of the widget dot grid and you give
7:42
the options here So let's see in the
7:43
practice how does it works So if I come
7:46
here okay if I come here Okay Uh let's
7:49
change this guys Uh do bye-bye bye-bye
7:53
and bye-bye Okay Let's delete those guys
7:56
Blah blah blah blah blah Stop there And
7:59
now it's this guy One two one Chase Uh
8:04
oh One and one One Okay Perfecto I do
8:08
this If I do this if I do this and if I
8:10
do this Okay For example to use grid we
8:12
have to do something like that Okay Grid
8:14
open and close So as we said we have is
8:17
like Excel sheet Okay We have row and we
8:19
have columns Let's give this guy for
8:21
them on the row So row is the line Okay
8:23
Like this Okay horizontal So on the row
8:26
zero okay let's keep all of them in the
8:28
row zero and then we have to give column
8:30
So we have to separate those attribute
8:32
those Okay but with column uh with comma
8:36
never forget that or else you are going
8:37
to get error Okay so let's see common uh
8:40
column Okay on column equal zero I save
8:44
If I run this we will see everything is
8:47
on top of everyone Okay so let me just
8:50
change the name here Uh because I don't
8:52
like these names Uh no no no no
8:58
Bye-bye Let's say one Okay which means
9:02
this guy is going to be two Oh I don't
9:04
know how to write three Okay I'm going
9:07
to figure out Okay two And this guy is
9:10
going to be three I think tree is like
9:13
something like this I'm not wrong Sorry
9:16
I don't speak Portuguese as my main
9:17
language I Uh oh I said this wrong Okay
9:20
sorry I don't speak English as a main
9:22
language Okay my main language my mother
9:24
tongue language is Portuguese Okay so
9:27
that's why I'm little confused how to
9:29
write So how to write it Four I think
9:30
four is like this way Okay four Two I
9:34
feel like this thing is wrong I don't
9:36
know Two I don't know Okay let's let's
9:38
keep it like something like that Okay
9:40
but I feel like this is wrong Okay no
9:42
problem So if I save this and if I
9:45
run Okay now we can see the things
9:48
properly Perfect So for this one is in
9:51
all of them that are in the row one Okay
9:53
as we can see here So this is the row
9:56
zero Okay the row zero So it always
9:58
start on zero 0 1 2 3 4 like that Okay
10:02
zero 1 2 3 4 is like this always So this
10:07
one is row zero and column zero So this
10:09
one will be on row one Okay and the
10:12
column zero No problem This one will be
10:14
row two Uh row three Okay perfect Save
10:18
And if I run this now we can see okay
10:21
one two three four Okay So now instead
10:24
of that let's see this guy come stay
10:26
here and this guy stay in the row zero
10:29
also and you come in the column one Okay
10:33
If I save this and if I run now you can
10:36
see okay all of them they are in the
10:37
column in the row zero Okay 0 0 and this
10:40
guy Okay Uh which one Uh which one is
10:44
this Three Okay Three is in the row two
10:46
Okay See stay in the row two Okay Uh
10:49
okay Now let's put something like 1 2 3
10:51
4 Okay So if you want to do one two
10:53
three four So now this guy stay this guy
10:56
can stay on one This stay on zero So
10:58
this will stay on one and this will stay
11:01
on the one Okay So row zero column one
11:06
column zero column one Okay Save If I
11:08
run this see now we have okay one two
11:12
three four So those are the geometry uh
11:16
geometry managers in tkindle Okay So
11:18
they are very useful for you to organize
11:20
okay for you to create your layout So
11:22
that's why for examp I prefer to use
11:25
grid in combination with place So I
11:27
think it's more easy okay because to be
11:29
honest pack is very difficult to know it
11:31
behavior Okay So it's kind of you don't
11:33
know properly how it's going to behave
11:35
when you use it So that's why I prefer
11:36
to use grid because you grid I can
11:38
control it and place place I can place
11:40
the things wherever I want Okay So
11:42
that's why I use more those two place
11:44
and grid but pack you can use but depend
11:47
how you'll be using it because to know
11:49
the behavior of the pack is complicated
11:51
to be honest is a little complicated
11:53
Those are uh the manager Okay The kind
11:57
manager Okay Geometry manager in the
11:59
Okay So those two they are Okay guys I
12:02
stay here I see you in the next video My
12:04
name is Juan Subscribeing to the channel
12:05
Give a like if you like this video and
12:08
see you Bye-bye
#Programming
#Development Tools
#Scripting Languages

