Python Tkinter: How to create a Combobox 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 Combobox 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 R so today we are going to
0:03
learn how we can create a combo box in
0:05
TI okay so a combo box are those options
0:08
box that we used to see in a lot of
0:09
application even web application okay so
0:12
we are going to learn how we can create
0:13
those box the same box okay in Python t
0:16
Okay so for that we can do something
0:19
like this so let me come to our test
0:22
editor but before that let's say what we
0:24
are going to do okay so in this video we
0:26
are going to do we are going to learn
0:28
how to create a combo box how to get how
0:30
to insert items inside of the combo box
0:33
okay and how to get the values from the
0:35
combo box okay and we are going to have
0:38
Al a lot of examples so let's go into
0:41
the test editor so for that let's do
0:43
something like this okay so we are going
0:45
to learn how to create a combo box in
0:47
Python t Okay so for that let's do
0:50
something like this so these are the
0:52
information from the previous video okay
0:54
so in order for us to get the info from
0:56
the combo box okay we can do something
0:59
like this okay uh I'm going to keep this
1:02
botton here we might need it but this
1:05
guy I'm going to delete this info even
1:08
here okay I can for now I can just
1:11
delete these guys okay I'm just going to
1:12
delete those guys so that we can have
1:14
more space to work and to play around so
1:19
for that let's do something like this
1:21
okay hi am here okay I have one label
1:25
and I have one entry so I don't need
1:27
this entry oh this is the label sorry
1:30
okay I don't need this label bye-bye and
1:33
if I save this and if I run this boom I
1:35
have only this bottom and this guy okay
1:37
perfect it gives error because we don't
1:39
have this entry anymore so I can just
1:41
remove this guy and write it pass so
1:44
that it can ignore okay if I click boom
1:46
boom it will pass it will ignore this
1:49
perfect though so in order to create the
1:51
combo box in Python we can do something
1:53
like this okay so first let's create one
1:56
variable called combo okay we can give
1:58
any name okay I'm just going give in
2:00
combo because it's easy name that can
2:02
pop up pop up on my head so for that we
2:05
can call combo box okay combo this way
2:10
combo box okay combo Box open and close
2:15
so if I save this and if I run boom I'm
2:18
going to get error why because in if you
2:22
want to use combo box okay we have to
2:24
call it from t. ttk Okay ttk so for that
2:30
we have to do something like like like
2:31
that okay we have to come here down we
2:32
have to do something like that from
2:36
theer okay from the dot
2:40
TK okay we can say
2:44
import space and axter all this way okay
2:48
now if I save this and if I run boom I'm
2:52
still getting error because he's saying
2:54
that ttk doesn't have this B&J so for
2:57
that to avoid this okay he saying that
2:59
this guy doesn't exist this guy okay so
3:02
to avoid this is very easy okay I can
3:04
just do like this you come out okay boom
3:08
you stay in the top and you stay down
3:09
okay boom I save and if I run boom
3:12
everything is working or I can just for
3:16
if I remove this guy and if I save like
3:18
this and keep like this I'm I'm still
3:20
getting error okay so that's why I put
3:23
that this way okay just change the
3:24
orders keep this way and safe everything
3:27
will work okay because combo box is in
3:29
inside of this one okay of this class so
3:33
now since we have a combo box okay let's
3:35
place it inside of our window let's say
3:38
window save okay and if I run this
3:42
nothing's going to happen Okay so now
3:45
after creating a combo box we need to
3:49
place it inside of the window okay so to
3:52
place inside of the window is the same
3:53
thing that we have been doing but let me
3:55
give a little space here let me say
3:58
combo Dot
4:00
okay so I'm just going to use this guy
4:03
okay you come
4:06
here and I will place it I place it here
4:10
okay so this is in Grid 0 one this guy
4:13
come in Grid one and this go down into
4:16
two okay I save this
4:18
and okay now I want this guy on zero
4:21
this guy on zero okay I save this combo
4:25
box if I save and if I run boom now we
4:28
have a combo box here okay but the combo
4:30
box is empty okay so we can give some
4:34
values here in our combo box in order to
4:36
give a value in the combo box we have to
4:37
do something like that okay here after
4:39
we place our combo box inside of window
4:41
below we can call combo okay we can just
4:45
open something like this okay inside of
4:48
a single quote we can call values this
4:51
way okay values
4:53
save give a little space and say equal
4:56
so now here we must give a dle or a list
5:01
so that those ones will be show inside
5:03
of our combo box okay so for example we
5:05
can say something like that okay uh if I
5:07
first I'm going to give a list okay so a
5:10
list of 1 2 3 4 five okay and save and
5:16
if I run
5:17
this if I come here we can see now we
5:20
have our values okay so apart of uh
5:25
apart of those okay we can give also
5:27
this one okay we can give Tuple inste of
5:30
lists I save if I run this uh we can say
5:34
we we have here our values okay so the
5:37
combo box it can be a mixer Val it can
5:39
be integer it can be float it can be
5:42
strings also for examp if I say comma
5:45
then I can say for example Jo which is
5:48
my name save and if I run this we can do
5:50
see like this is here down okay just
5:53
this and it will be working so this is
5:55
how we can create a combo box in Python
5:57
ticking there okay so but that this is
5:59
there is a thing which is very very very
6:02
important okay that is how to get the
6:04
value from the combo box and make use of
6:06
it but aart of that okay when we create
6:09
a combo box we can also Define which
6:11
value we want it to show first for if I
6:13
save this and if I run for examp here we
6:16
can see this guy is z is not shown
6:18
anything okay but we can set a for a
6:21
default value for I can set for
6:23
something like that okay combo dot
6:26
current okay current
6:29
H equal for I can say here it works as a
6:33
position okay for I want the this number
6:36
one to be to be shown as the first value
6:39
for if I put it one okay you come here
6:42
no if I put it one save if I run this is
6:46
going to show me two why because see
6:49
this one it works as index okay this one
6:51
this thing that we are passing is index
6:53
of the tle okay of the value in the T So
6:57
since we gave one it's showing two
6:58
because it start from 0 1 2 three okay
7:02
but if you want one we have to give it
7:04
zero here Zero Save then if we save so
7:08
that we can see it's showing now one as
7:10
the default value okay so if we open
7:12
this 1 2 3 4 and done for if you want to
7:15
dra okay which is the last one so the
7:18
last one is let me see 0 1 2 3 4 5 it's
7:23
five okay if I give five save and if I
7:26
run it show okay let me see if I if is
7:30
uh negative number Works see if I put
7:33
minus oneus one is supposed to give me
7:35
Al safe if I run boom is wrong so that
7:38
means a negative number doesn't work
7:40
only positive numbers it will work okay
7:44
but since this is a to let me change let
7:46
me check for a list sorry if I delete
7:51
this guy and instead of to if I pass the
7:54
list and if I keep there minus one save
7:56
and if I run boom even minus one doesn't
8:00
work so it means only positive numbers
8:02
can be assigned there okay save and I
8:04
one now we have two8 as default so let's
8:08
put one which is zero okay Zero Save and
8:11
if I run boom we have this guys in order
8:15
to get the values from the combo box we
8:18
have to do something like that okay
8:20
inside here
8:21
our uh this function hello we can do
8:24
something like that okay H from there
8:26
here let me say let me create one uh
8:29
variable called info this info will be
8:32
equal we have to call the N of the the
8:34
name of the combo box which is combo dot
8:36
we we use get the function get Al to get
8:39
the values from the combo box then do
8:42
this okay so we can print the value okay
8:45
print what we are going to print we are
8:47
going to print info okay which is the
8:49
information so if I save this and if I
8:52
run okay let me see uh if I click any
8:56
value let's for if I click here boom it
8:59
print one okay it's getting the value
9:01
from the combo box if I change to four
9:04
boom it's printing four and so on okay
9:07
so this is how we can get the values
9:08
from the combo box in Python T So after
9:12
get we get those values we can do
9:13
whatever we want we can manipulate those
9:15
values as we
9:18
wish so guys if you like this video
9:20
please subscribe to the channel give a
9:21
like to the video and see you in the
9:23
next video okay bye-bye