In this Python Tkinter tutorial for beginners, you'll learn how to build your first graphical user interface (GUI) using Python.
Tkinter is Python's built-in GUI library, meaning you don't need to install anything extra to start creating desktop applications.
In this lesson, you'll learn:
✅ What Tkinter is
✅ Why Tkinter is great for beginners
✅ How to create your first window
✅ How to set a window title
✅ How to change the window size with `geometry()`
✅ How `mainloop()` works
✅ How to change the window background color
This video is the first lesson of a complete Tkinter course where we'll build several beginner-friendly desktop applications and finish with a real-world Currency Converter App.
If you're learning Python and want to create desktop applications, this series is the perfect place to start.
👍 Don't forget to Like, Subscribe, and turn on notifications so you never miss the next lesson.
Show More Show Less View Video Transcript
0:00
Hello guys, welcome back to the channel.
0:01
So, in this part of the inter crash
0:03
course, we are going to learn a little
0:04
bit about this Python module that help
0:06
us to create
0:08
graphical user interface in Python. So,
0:11
what is Tkinter? Tkinter is a Python
0:12
most popular graphical user interface.
0:14
So, Tkinter is available in the most of
0:16
platforms such as Linux, Unix, Windows,
0:18
even Mac. And with it, it's very easy to
0:22
create a desktop application. And it
0:24
also help to create a prototype for your
0:26
apps. And the best thing of that is that
0:29
Tkinter, you don't need to install it
0:31
because it comes built-in with Python.
0:33
Once you install Python, you are ready
0:34
to make use of Tkinter.
0:37
So, in this crash course, we are going
0:38
to have a little introduction about the
0:39
Python Tkinter. We will create our first
0:41
windows. We will learn about some
0:43
widgets that Tkinter offer us. We learn
0:46
about the geometry manager, creating
0:48
also a full complete project, which is
0:51
this one of currency converter. So, in
0:52
this project that we are going to create
0:54
in the end of this same crash course,
0:56
it's very easy. Okay, so this is the app
0:57
that help us to convert one currency
0:59
into another one. For example, here we
1:01
have $1, okay?
1:02
We were We are going to to convert this
1:04
$1 into Brazilian currency, which is
1:07
real. So, if I put in $1, and it will
1:11
show us, for example, $1 in Brazilian
1:14
real, it's it's equivalent into 5.10,
1:18
okay? reals. So, if I enter different
1:20
number, for example, five, then I just
1:22
hit converter, it's going to loading,
1:24
then it's going to give us the result.
1:26
For example, $5 into Brazilian currency
1:29
is equal 25.48
1:32
reals. So, I can exchange also, for
1:34
example, if I want $1 to any another
1:36
currency, for example, I want if I want
1:38
euro, AOA, which is the currency that we
1:40
use in my country, I'm from Angola, even
1:43
Indian rupees. So, there is a lot of
1:45
currencies. Let me check, for example,
1:46
Indian rupees. So, which means $5 into
1:49
Indian rupees is equal it's equal it's
1:52
equivalent into
1:54
4
1:55
76.77,
1:57
okay? rupees.
1:59
This is what you're going to get. Also,
2:00
the same we can do a post positive
2:02
rupees to rupee, okay?
2:06
Maybe let's choose another thing, for
2:07
example, rupee into
2:10
this one, which is my currency, okay?
2:12
For example, 5 rupees is equal 49
2:15
Angolan kwanza.
2:17
Okay? So, this will be the final project
2:19
that we are going to create. And also,
2:22
while the course will keep going on, we
2:23
will create also some small apps like
2:25
that, but this will be the final one
2:27
that we will create.
2:28
So, now the next step will be to create
2:30
our first window in Python Tkinter. As I
2:33
said in the beginning, okay? We don't
2:34
need to install Tkinter. Tkinter, we
2:36
just need to import it and make use of
2:38
Tkinter. So, how we can do that? It's
2:40
very easy.
2:41
You just open your code editor. I'm
2:43
going to use VS Code. I will also, if
2:45
you're a beginner, I will also recommend
2:47
you to make use of VS Code because it is
2:49
beginner-friendly and it's very easy to
2:51
go on.
2:53
So, the first thing that we're going to
2:54
do is
2:56
We didn't need just to import Tkinter
2:57
from Tkinter, something like this. From
2:59
Tkinter import
3:02
all. So, this will be us saying, okay?
3:05
Import everything that is inside Tkinter
3:07
into this script.
3:09
Then, after that, let's now create our
3:11
first window. In order for us to create
3:12
the first window is like this. First, we
3:14
need to create an instance of Tkinter.
3:16
So, I'm going to create a variable
3:17
called window.
3:19
This way, window. So, my window will be
3:21
equal
3:22
Tk. We need to import this. See, don't
3:24
forget that this first T is a capital T,
3:27
then the K is a small K, okay? I will
3:30
just do something like this. So, this
3:32
way, I just say create an instance of
3:35
Tkinter.
3:36
Then, I'm going to save this. So, after
3:38
we create the instance of Tkinter
3:40
library, now this same instance, it has
3:43
title, it has
3:45
geometry, it has a some configuration.
3:47
So, now let's give a title for our
3:48
window. So, in order for that, I'm I'm
3:50
going to call the same instance, for
3:51
example, window
3:52
After If I want to give a title for my
3:54
window, I just call it title this way,
3:57
open and close. And here inside
4:00
Okay, we need to give a title. So, I'm
4:02
just I can say something, for example,
4:04
hello.
4:06
Okay, hello world.
4:09
Boom, it's a good title. So, after that,
4:11
I'm going to start the event loop. So,
4:13
this event loop is the one that will
4:14
help me to run, or better to show the
4:17
window in our
4:20
screen. Okay, so in in order for that,
4:22
I'm just need to do this. Window, get
4:23
the same instance, dot main, okay, loop.
4:28
So, every time when you
4:30
create a window in Tkinter, it's very
4:33
important for you to call this line.
4:35
Because if you call if you don't call
4:37
this line, okay, and if you try to run
4:39
your app, it will not show in your
4:40
screen, for example, okay. Let me
4:41
comment first this line. I'm going to
4:44
comment this thing.
4:45
Okay, save, then I'm going to try now to
4:47
run this to see what's going to happen.
4:56
See, as you can see, okay, it run, but
4:59
you cannot see the result. It's It will
5:01
run very fast, but we cannot see the
5:02
result. In order for us to see the
5:03
result, that's why I said it's very
5:05
important for us to call this line.
5:07
What this line does? See, this line it
5:10
it start the
5:12
event loop, okay, so that the window can
5:14
keep it in our screen. So, let me
5:17
comment it, okay. Start
5:20
the event loop.
5:23
This is one of the most important line
5:25
in Tkinter.
5:26
After this, I just need to run this now
5:28
again.
5:29
Then, boom, we are going to see our
5:31
first window here, okay. As you can see,
5:34
this is our first window in Python
5:37
Tkinter, okay. So, now
5:39
inside of this window is where we will
5:41
put everything that we need
5:44
from, okay, that we need it to be
5:46
showing in our app. So, we will put
5:48
everything inside of this. So, this same
5:51
window, okay?
5:52
We can also specify the
5:55
size of it, for example, the width and
5:57
the height of the window. Because the
5:59
way that it is, if I run
6:01
it will it's going to give like a random
6:03
size
6:04
to it, as you can see, okay? But, we can
6:06
also define the size of it, for example,
6:08
the width and the height of window. In
6:11
order to do that, I just can do
6:12
something like this, window {dot}
6:15
geometry, okay? Geometry, this one.
6:18
Then, I will open and close. Then, here
6:21
inside I need to pass it as a string
6:23
always, okay? Here inside, the first
6:25
value that we're going to give is for
6:27
width. For example, I can give 500.
6:30
Then, I will uh give X.
6:34
Okay, the second value that I'm going to
6:36
give will be for the height, okay? I can
6:38
say, for example, 500 500.
6:40
Save this, and if I run
6:45
then, as you can see, now it's giving a
6:48
different size in my window, okay? For
6:50
example, I can give a different one, for
6:52
example, okay?
6:54
250, okay?
6:56
250, 500 250. Save, and if I run this
7:04
then, boom, as you can see, now it's
7:05
giving a different size of our window.
7:10
Then, apart of that, also, we can
7:11
configure the background color of our
7:14
window. In order for us to do that, I
7:15
can do something like this, for example.
7:17
I will just call the same instance,
7:18
okay? Window {dot}
7:21
{dot} what? Configure, this way,
7:23
configure. Then, I'm going to open and
7:26
close. Then, if I want to give a
7:28
background color, there is abbreviation
7:30
for that. I can just give something like
7:31
this, BG. BG stand for background, okay?
7:35
Then, I will say BG will be equal and
7:37
I'm going to give something like this,
7:39
okay? Always must be as a string. See?
7:42
Here, I can give also like a hexadecimal
7:44
values, colors. Okay? Then, uh
7:47
I will just I'm just going to do
7:48
something like this. I will give
7:49
something like blue.
7:51
Save.
7:52
Then, if I run this now,
7:58
boom, as you can see, our window has
7:59
changed into blue. Okay?
8:01
Then, I can give also for some different
8:03
color. If I give us some green, okay?
8:06
Green. Save. And if I run some It's very
8:10
important for us first to close.
8:12
Then,
8:13
if I run this,
8:19
and boom, as you can see now, our
8:20
background color is green. Okay? See, we
8:23
know that the native colors is kind of a
8:26
little ugly, ugly. Okay? So, we can give
8:29
a better like derivative color
8:30
derivative colors, which make sometimes
8:32
the apps looks better. So, in order for
8:34
us to do this, we can do something like
8:36
this. We can come here, okay? In our
8:38
browser and do something like this.
8:41
Color picker, okay? Color
8:44
picker. Okay? Color picker. So, from
8:47
color picker, we can get some any
8:48
hexadecimal color, which are very good.
8:51
Okay?
8:52
For example, if I come here, and I can
8:54
get any a better color.
8:56
Okay, I think I like this color. I can
8:58
just come and copy this color here. And
9:00
if I come to my VS code, and I can just
9:02
give it here. Okay? I'll hexadecimal
9:05
color. I'm going to save this. I'm going
9:08
to close this one, which is running. And
9:10
if I run again,
9:12
okay, I just run.
9:14
Let's see our the result.
9:16
And boom, now we have a better color.
9:18
Okay? So, this is how you can give a
9:20
color
9:22
into the Kinder app. Okay? You can give
9:24
either like the native colors, or you
9:25
can give like hexadecimal
9:28
colors. So, I prefer to give this way
9:29
for me, cuz I think this way I can get a
9:32
better result.
9:33
So, even I can play for example here.
9:35
No, I don't like too much
9:37
blue. I think this one is good. Let me
9:40
save. Close this one.
9:44
And if I run it again, let's see the
9:46
result.
9:48
And boom, the background color just
9:50
changed.
9:51
So, this is the way that you can change
9:53
the background color in Python Tkinter.
#Science

