The Wayback Machine - https://web.archive.org/web/20240710021953/https://www.geeksforgeeks.org/combobox-widget-in-tkinter-python/
Open In App

Combobox Widget in tkinter | Python

Last Updated : 23 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

Python provides a variety of GUI (Graphic User Interface) types such as PyQT, Tkinter, Kivy, WxPython, and PySide. Among them, tkinter is the most commonly used GUI module in Python since it is simple and easy to understand. The word Tkinter comes from the Tk interface. The tkinter module is available in Python standard library which has to be imported while writing a program in Python to generate a GUI.

Note: Tkinter(capital T) is different from the tkinter. Tkinter is used in Python2.x and is changed to tkinter in Python.3x.

Combobox is a combination of Listbox and an entry field. It is one of the Tkinter widgets where it contains a down arrow to select from a list of options. It helps the users to select according to the list of options displayed. When the user clicks on the drop-down arrow on the entry field, a pop up of the scrolled Listbox is displayed down the entry field. The selected option will be displayed in the entry field only when an option from the Listbox is selected.

Syntax:

combobox = ttk.Combobox(master, option=value, ...)

Example 1: Combobox widget without setting a default value.




# python program demonstrating
# Combobox widget using tkinter
  
  
import tkinter as tk
from tkinter import ttk
  
# Creating tkinter window
window = tk.Tk()
window.title('Combobox')
window.geometry('500x250')
  
# label text for title
ttk.Label(window, text = "GFG Combobox Widget", 
          background = 'green', foreground ="white", 
          font = ("Times New Roman", 15)).grid(row = 0, column = 1)
  
# label
ttk.Label(window, text = "Select the Month :",
          font = ("Times New Roman", 10)).grid(column = 0,
          row = 5, padx = 10, pady = 25)
  
# Combobox creation
n = tk.StringVar()
monthchoosen = ttk.Combobox(window, width = 27, textvariable = n)
  
# Adding combobox drop down list
monthchoosen['values'] = (' January', 
                          ' February',
                          ' March',
                          ' April',
                          ' May',
                          ' June',
                          ' July',
                          ' August',
                          ' September',
                          ' October',
                          ' November',
                          ' December')
  
monthchoosen.grid(column = 1, row = 5)
monthchoosen.current()
window.mainloop()


Output:

Example 2: Combobox with initial default values.
We can also set the initial default values in the Combobox widget as shown in the below sample code.




import tkinter as tk
from tkinter import ttk
  
# Creating tkinter window
window = tk.Tk()
window.geometry('350x250')
# Label
ttk.Label(window, text = "Select the Month :", 
        font = ("Times New Roman", 10)).grid(column = 0, 
        row = 15, padx = 10, pady = 25)
  
n = tk.StringVar()
monthchoosen = ttk.Combobox(window, width = 27, 
                            textvariable = n)
  
# Adding combobox drop down list
monthchoosen['values'] = (' January', 
                          ' February',
                          ' March',
                          ' April',
                          ' May',
                          ' June', 
                          ' July', 
                          ' August', 
                          ' September', 
                          ' October', 
                          ' November', 
                          ' December')
  
monthchoosen.grid(column = 1, row = 15)
  
# Shows february as a default value
monthchoosen.current(1) 
window.mainloop()


Output:



Previous Article
Next Article

Similar Reads

Autocomplete ComboBox in Python-Tkinter
Prerequisites: Python GUI – tkinter The Listbox widget is used to display a list of items from which a user can select a number of items. But have you ever wondered, how to return the list of possible results when a key is pressed? Let's see the following approach towards the same. Working of Program List consisting of words is initialized. Entry b
2 min read
How to get the index of selected option in Tkinter Combobox?
In this article, we will be discussing how to get the index of the selected options in the Tkinter Combobox. A Combobox is a combination of a Listbox and an Entry widget. This widget allows users to select one value from a set of values. Syntax: def get_index(*arg): Label(app, text="The value at index " + str(combo.current()) +\ " is" + " " + str(v
3 min read
Difference Between The Widgets Of Tkinter And Tkinter.Ttk In Python
Python offers a variety of GUI (Graphical User Interface) frameworks to develop desktop applications. Among these, Tkinter is the standard Python interface to the Tk GUI toolkit. Tkinter also includes the 'ttk' module, which enhances the visual appeal and functionality of the applications. In this article, we will cover the differences, providing a
4 min read
Python | Menu widget in Tkinter
Tkinter is Python’s standard GUI (Graphical User Interface) package. It is one of the most commonly used package for GUI applications which comes with the Python itself. Menus are the important part of any GUI. A common use of menus is to provide convenient access to various operations such as saving or opening a file, quitting a program, or manipu
2 min read
Progressbar widget in Tkinter | Python
The purpose of this widget is to reassure the user that something is happening. It can operate in one of two modes - In determinate mode, the widget shows an indicator that moves from beginning to end under program control. In indeterminate mode, the widget is animated so the user will believe that something is in progress. In this mode, the indica
2 min read
Python | PanedWindow Widget in Tkinter
Tkinter supports a variety of widgets to make GUI more and more attractive and functional. The PanedWindow widget is a geometry manager widget, which can contain one or more child widgets panes. The child widgets can be resized by the user, by moving separator lines sashes using the mouse. Syntax: PanedWindow(master, **options) Parameters: master:
3 min read
Python Tkinter - Toplevel Widget
Tkinter is a GUI toolkit used in python to make user-friendly GUIs.Tkinter is the most commonly used and the most basic GUI framework available in Python. Tkinter uses an object-oriented approach to make GUIs. Note: For more information, refer to Python GUI – tkinter Toplevel widget A Toplevel widget is used to create a window on top of all other w
3 min read
Python Tkinter - Entry Widget
Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. Python with Tkinter is the fastest and easiest way to create GUI applications. Creating a GUI using Tkinter is an easy task.In Python3 Tkinter is come preinstalled But you can also install it by using
3 min read
Python Tkinter - ListBox Widget
Tkinter is a GUI toolkit used in python to make user-friendly GUIs.Tkinter is the most commonly used and the most basic GUI framework available in python. Tkinter uses an object-oriented approach to make GUIs. Note: For more information, refer to Python GUI – tkinter ListBox widget The ListBox widget is used to display different types of items. The
2 min read
Python Tkinter - Scale Widget
Tkinter is a GUI toolkit used in python to make user-friendly GUIs.Tkinter is the most commonly used and the most basic GUI framework available in python. Tkinter uses an object-oriented approach to make GUIs. Note: For more information, refer to Python GUI – tkinter Scale widget The Scale widget is used whenever we want to select a specific value
2 min read
three90RightbarBannerImg