Set a default value for a ttk Combobox in Tkinter?

Tkinter Combobox is used to add a drop-down menu to the Entry widget, making it useful to handle multiple data of any application. A Combobox widget can be created using the Combobox(arguments). However, for the particular need of an application, we can set the default value for the Combobox widget. It can be set by listing all the records in a variable that needs to be present in the Combobox. By specifying the index of the particular value in the current(index) method, we can set the default value in the Combobox widget.


#Import Tkinter library
from tkinter import *
from tkinter import ttk
#Create an instance of Tkinter frame or window
win= Tk()
#Set the geometry of tkinter frame
#Create a Combobox
combobox= ttk.Combobox(win,state= "readonly")
combobox.pack(pady=30, ipadx=20)


Running the above code will display a window that contains a Combobox with some default value. We can change the default value by changing the index of the current method.

Updated on: 22-Apr-2021

13K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started