Python Tkinter: How to Create a Window 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 Window in Tkinter 💖 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: 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 here we are going to start
0:03
with tickin python so so what is tickin
0:06
so tickin is the python popular okay gu
0:08
GUI key that means graphical user
0:11
interface okay library to create desktop
0:14
app so T is the standard library in
0:16
Python so T it has a lot of widget that
0:19
can help us creating a standard
0:21
application in python as I said in the
0:23
beginning the main objective of this
0:25
course is for you to practice python to
0:27
put in practice everything that you know
0:28
about python Okay so so TI in will be
0:30
the best choice for you okay by learning
0:32
TI in so that you can create some
0:33
standard application in Python windows
0:35
in TI in so here we are going to create
0:37
a Windows in okay so the main operation
0:40
that we are going to perform in this
0:41
video will be okay we'll learn how to
0:42
create a Windows in okay we'll learn how
0:45
to set a teer window title how to set
0:48
teer size okay uh not t window size okay
0:52
we learn how to change the size of a
0:53
window teer we learn how to change also
0:55
the tier Windows background color we can
0:57
change Al the background color we learn
1:00
also okay how to change this icon here
1:03
iner and we also learn how to keep the
1:08
window size okay non recal okay so that
1:11
we cannot change the size of window
1:13
intake so this will be the operation
1:14
that we are going to perform in this
1:16
video so going to my code editor so so
1:19
here I'm going to use subliner okay so
1:21
the first step is for you to have python
1:23
installed in your laptop so after that
1:25
ticker we don't need to install ticker
1:27
okay the only thing that we need to do
1:29
is to import 4S okay so but the first
1:31
thing that you have to do is you have to
1:32
create one uh new script okay you can
1:35
call it as you want so I create mine I
1:37
call it main. P so here in order to use
1:40
the interface we have to do the first
1:41
thing is like that okay so the first
1:43
step to create a window in tier is by
1:48
doing this from tier okay from
1:52
tier
1:55
import all okay so so this way we are
1:58
import everything inside the
2:00
here okay so that we can make use after
2:02
we imported theer so in order for us to
2:03
create a window we have to do something
2:05
like that we have first to create one
2:07
one variable okay so this VAR we can
2:09
call it as window no problem so then
2:10
that we have TK okay TK open and close
2:16
so this this way we are initiating okay
2:19
the T window so after that we can change
2:23
a title of of window in so for that we
2:27
have to do something that window
2:30
dot title Okay window do title open and
2:33
close so here inside okay we'll uh we'll
2:36
give the name of our window okay so for
2:38
that it will be let me see uh first
2:41
window or we can say just hello word
2:45
hello word okay hello word I save so
2:50
after we Define a title in window C so
2:54
it is very important for us to keep our
2:56
teab running constantly for example like
2:59
that if I run this code like the way
3:01
that it is safe if I run this so it will
3:04
run but it will not show anything so for
3:07
us to keep the window here okay we have
3:11
to do something like that
3:13
window dot main Loop okay open close
3:18
save so this way when we'll run this
3:21
okay so we'll keep this window here okay
3:23
so it'll keep running like inside of
3:26
loop until we close it but when we don't
3:28
give this okay you might have this
3:30
problem okay see if you don't give this
3:31
the in M Loop save if you run just like
3:34
that nothing will happen it's like it
3:35
will execute but it won't show you
3:37
anything okay so in order for us to keep
3:40
that we have to write that the window do
3:43
main Loop okay this way so then if you
3:45
save as we can see here okay now we have
3:48
here hello world okay which is the name
3:50
of which the title of our Windows now we
3:53
have our main window so this window we
3:54
can resize it okay we can change the
3:57
size something like that so the next
3:59
step is okay we can change also the size
4:02
of our window in okay so for that we
4:05
have to do something like that okay in
4:06
order to change the size of window we
4:08
have to do something like that we have
4:09
to call again window okay dot so for
4:13
that we use some uh some property called
4:16
geometry okay I will open and close so
4:18
here inside geometry okay it can be
4:21
inside of one single quot or double
4:23
single C something like that no problem
4:25
then we'll pass the dimensions of window
4:28
that we wish so for example I'm I'm
4:29
going to give 250 okay for width okay
4:34
the first one is for width x or X then
4:38
250 sorry 250 the second one is for H
4:41
okay so this first one is for WID and
4:44
this one is for H so after that if I
4:46
save this and if I run we can see now is
4:50
G me a different size okay so if I open
4:53
this okay if I open this okay let me try
4:56
to increase the width okay for example
4:58
here let me give at least 550 I save if
5:01
I run this we can see that the size of
5:05
the window is increased okay so the same
5:07
way also we can increase the a the
5:09
height of the window let me see if I
5:12
give 50 500 if I save in that I run it
5:15
that we can see this is the way that we
5:16
can change the size of a window okay in
5:20
so we can change also the background
5:22
color of our Windows okay for that we
5:24
have to do something like that okay if I
5:26
come down here let me see window okay we
5:29
have to call window again dot so for
5:31
that we have to call something called
5:33
configure okay
5:34
configure this way configure open and
5:37
close sorry not configure but see config
5:41
okay the the short form config we have
5:44
to open like this so after that okay we
5:47
can give a property like BJ so BJ stand
5:50
for background okay so BJ equal so after
5:54
that here we can give any color that we
5:56
wish okay uh for example let me give uh
5:59
blue okay I open and close I do
6:02
something blue I save and I run it
6:06
change the color background color to
6:07
Blue so even we can change it for green
6:10
if you wish green oh oh I get it wrong
6:14
green I save I run boom it change color
6:18
as a green so the best way to do this is
6:20
that okay for examp if you're looking
6:21
for a good color okay there is another a
6:23
better way that you can give a color
6:25
here so this way is that so another way
6:28
is that okay you can come to Google okay
6:30
just uh just search for color peer color
6:34
peer okay color peer so if you search
6:38
for color Pi for example here you have a
6:39
lot of colors that you can choose okay
6:41
for examp let us give the background
6:43
color for example okay we can play for
6:46
this one for this color I like this
6:47
color so you can just copy here okay you
6:49
can give us ex decimal copy and if you
6:52
come here okay you can give directly
6:55
here that color that you just copy sorry
6:58
so it always start with Ash uh okay
7:01
ashtag so like this save if we run this
7:05
let me see boom we change the color to
7:07
this one okay so this is another way so
7:09
that you can give uh color to your
7:12
window okay to your background window so
7:16
after that we said that so we are going
7:17
to perform which operation let's see how
7:19
to create a window we already that how
7:21
to change the title of the window we did
7:24
that okay size also we did background
7:27
color so then let's learn also how we
7:29
can change that icon here on the top of
7:32
the wind okay so for that we have to do
7:33
something like this okay let me see I
7:35
will close this okay so in this my
7:38
folder the okay where I'm writing where
7:41
where I'm saving my script I have to do
7:42
something like that okay I'm coming here
7:44
let me go after I come here okay let me
7:48
search any picture let me come in my
7:49
downloads so I have some picture here
7:52
okay let me get it Leist no this one is
7:54
too small okay at least this logo okay
7:57
this python logo so now this one is
7:59
better I'll copy here I'm going back
8:01
I'll paste it here okay so this my image
8:05
is on let me see which format is I think
8:07
is a PNG format okay yeah it's a PNG
8:10
format so I'm just going to change the
8:12
name for a better name okay easy name
8:14
I'll write for for example logo okay
8:18
logo so the first thing is that we have
8:20
to have the icon or the photo the image
8:23
anything okay near to the script so
8:25
after that I can just come here to my
8:28
okay here and I can do something like
8:30
that for example I can I will create one
8:32
image uh sorry one variable called like
8:34
icon icon this icon will be equal to I'm
8:37
going to call photo image oh Sor I wrote
8:40
it wrong photo so after that I'm going
8:43
to call photo image like this
8:45
photo image photo image open close okay
8:48
so here inside the photo image I have to
8:50
give one attribute called file okay so
8:53
this file will be equal to okay I open
8:56
and close this file I'm going to give
8:58
this my image here okay so since they
9:00
are in the same directory I can just
9:01
give something like
9:04
logo.png okay something like this then I
9:06
will save so after that to make use of
9:09
this icon okay like this for examp if I
9:11
run this let me see I run I didn't get
9:14
any error okay it means everything is
9:16
okay so to get that icon here okay to
9:19
get that image here I have to do
9:21
something like this I'm just going to
9:23
give a space then I can just give
9:25
something like that okay window okay
9:27
window. w okay uh
9:31
WM underscore underscore
9:35
icon okay icon photo this way open and
9:39
close so here I'm just give I will give
9:42
that icon okay this image this image uh
9:45
if I save this and if I run let me see I
9:48
got one error so uh yeah I got error
9:51
because before I give this icon first I
9:53
have to give another paramet another
9:55
argument which is true this way okay
9:57
true comma then I'll give my icon like
10:01
this okay I will save then I will run
10:04
and we can see that it changed the icon
10:06
here okay now it's using that image as
10:08
icon okay so I use this way so that this
10:10
way it can give for multiple platform
10:12
okay it doesn't matter if it is in
10:14
Windows on Linux or maybe in Mac OS okay
10:17
so you giving this way is better so this
10:20
is the best way that you can give icon
10:22
here so this is the way that you can
10:24
change the icon on t Okay so guys this
10:27
video will stay here okay I I'll keep in
10:30
the description a link uh which has a
10:33
tutorial about this what I just told
10:35
here okay so if you don't get from the
10:36
video you can go from the link and learn
10:38
from there also okay so any doubt just
10:40
comment in the section and we are good
10:42
to go okay so thank you see you in the
10:45
next video give a like on this video And
10:47
subscribe to the channel okay my name is
10:50
and see you in the next video bye
#Scripting Languages
#Software