
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
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.
Example
#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 win.geometry("750x250") #Create a Combobox combobox= ttk.Combobox(win,state= "readonly") combobox['values']=('C++','Java','Python') combobox.current(2) combobox.pack(pady=30, ipadx=20) win.mainloop()
Output
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.
- Related Articles
- How to set a default string value on a Tkinter Spinbox?
- How to set default text for a Tkinter Entry widget?
- How to disable a Combobox in Tkinter?
- How to set a default parameter value for a JavaScript function?
- How do I set the default value for a column in MySQL?
- Tkinter Spinbox Widget Setting Default Value
- Changing the appearance of a Scrollbar in Tkinter (using ttk styles)
- How to set default value for empty row in MySQL?
- Set default value to a JSON type column in MySQL?
- Set a default value for the argument to cover undefined errors while calling a function in JavaScript
- Set a default row size for CSS Grid
- Configure tkinter/ttk widgets with transparent backgrounds
- How can I set the default value of my Tkinter Scale widget slider to 100?
- How to set NOW() as default value for datetime datatype in MySQL?
- How can I set the default value for an HTML element?

Advertisements