A Python Tkinter Combobox is a drop-down list that allows the user to select a value from a list. The list of values is defined by the “values” option, and the currently selected value is stored in the “textvariable” option. The Combobox widget is a combination of an Entry widget and a Listbox widget.
Here’s an example of how to create a Tkinter Combobox:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import tkinter as tk import tkinter.ttk as ttk root = tk.Tk() root.geometry("200x200") # create a variable to store the selected value selected = tk.StringVar() # create the combobox combobox = tk.ttk.Combobox(root, textvariable=selected) combobox.grid(row=0, column=0) # set the values for the combobox combobox["values"] = ["Option 1", "Option 2", "Option 3"] # set a default value for the combobox combobox.set("Option 1") root.mainloop() |
This code will create a Tkinter window with a Combobox that has the options “Option 1”, “Option 2”, and “Option 3”. The currently selected value is stored in the “selected” variable, which can be used to retrieve the value and use it in your program.
Run the complete code and this will be the result

Here’s an example of how you can add a label that displays the selected item from the Combobox:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import tkinter as tk import tkinter.ttk as ttk root = tk.Tk() root.geometry("200x200") # create a variable to store the selected value selected = tk.StringVar() # create the combobox combobox = tk.ttk.Combobox(root, textvariable=selected) combobox.grid(row=0, column=0) # set the values for the combobox combobox["values"] = ["Option 1", "Option 2", "Option 3"] # set a default value for the combobox combobox.set("Option 1") # create a label to display the selected item label = tk.Label(root, textvariable=selected) label.grid(row=1, column=0) root.mainloop() |
In this code, I’ve added a label after the Combobox, and set its textvariable to be the same as the Combobox’s textvariable. This means that whenever the user selects a new item from the Combobox, the label will automatically update to display the selected item.
Run the complete code and this will be the result

You can also add a function to update the label when you change the combobox selection using the command attribute of the combobox, like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import tkinter as tk import tkinter.ttk as ttk root = tk.Tk() root.geometry("200x200") # create a variable to store the selected value selected = tk.StringVar() # create a label to display the selected item label = tk.Label(root, textvariable=selected) label.grid(row=1, column=0) def on_select(selected): label.configure(text=selected.get()) # create the combobox combobox = tk.ttk.Combobox(root, textvariable=selected, command=on_select(selected)) combobox.grid(row=0, column=0) # set the values for the combobox combobox["values"] = ["Option 1", "Option 2", "Option 3"] # set a default value for the combobox combobox.set("Option 1") root.mainloop() |
Now, the label will display the selected option from the combobox every time you change the selection.
Learn More on TKinter GUI
- How to Create Conutdown Timer with Python & TKinter
- Create GUI Applications with Python & TKinter
- Python TKinter Layout Management
- How to Create Label in TKinter
- How to Create Buttin in Python TKinter
- Build Music Player in Python TKinter
- How to Build Calculator in Python TKinter
- How to Build Weather App in TKinter
Here is an example of a simple weather application using Tkinter and OOP (Object-Oriented Programming) in Python:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
import tkinter as tk from tkinter import ttk class WeatherApp(tk.Tk): def __init__(self): super().__init__() self.title("Weather App") self.geometry("200x200") self.city_label = tk.Label(self, text="Select a city:") self.city_label.grid(row=0, column=0, padx=10, pady=10) self.city_var = tk.StringVar() self.city_combo = ttk.Combobox(self, textvariable=self.city_var, state="readonly") self.city_combo["values"] = ["New York", "Los Angeles", "Chicago", "Houston", "Phoenix"] self.city_combo.current(0) self.city_combo.grid(row=0, column=1, padx=10, pady=10) self.result_label = tk.Label(self, text="Weather:") self.result_label.grid(row=1, column=0, padx=10, pady=10) self.result_var = tk.StringVar() self.result_var.set("N/A") self.result_display = tk.Label(self, textvariable=self.result_var) self.result_display.grid(row=1, column=1, padx=10, pady=10) self.get_weather_button = tk.Button(self, text="Get Weather", command=self.get_weather) self.get_weather_button.grid(row=2, column=1, padx=10, pady=10) def get_weather(self): city = self.city_var.get() if city == "New York": self.result_var.set("Sunny") elif city == "Los Angeles": self.result_var.set("Cloudy") elif city == "Chicago": self.result_var.set("Rainy") elif city == "Houston": self.result_var.set("Hot") elif city == "Phoenix": self.result_var.set("Warm") else: self.result_var.set("Invalid city") if __name__ == "__main__": app = WeatherApp() app.mainloop() |
In this example, the WeatherApp
class is defined which inherits from the tk.Tk
class. In the __init__
method, various widgets such as labels, a combobox, and a button are created and placed on the GUI using the grid
layout manager. The combobox is populated with a list of cities and is set to be “readonly” so that the user can only select one of the options provided. The button is configured to call the get_weather
method when clicked.
The get_weather
method retrieves the currently selected city from the combobox and uses an if loop.
Run the complete code this will be the result.
