
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- How to set a default string value on a Tkinter Spinbox?
- How to disable a Combobox in Tkinter?
- How to set default text for a Tkinter Entry widget?
- 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
- Set a default row size for CSS Grid
- How to set default value for empty row in MySQL?
- Changing the appearance of a Scrollbar in Tkinter (using ttk styles)
- 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
- Configure tkinter/ttk widgets with transparent backgrounds
- How to use a function for default value in MySQL?
- How to set NOW() as default value for datetime datatype in MySQL?
- Set DEFAULT values for columns while creating a table in MySQL
Advertisements