
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Disable a ComboBox in Tkinter
The Combobox widget is similar to the OptionMenu widget in Tkinter which gives the user a choice to select from the group of options. The Combobox widget allows users to select the option with an Entry widget that adds selected menu items from the dropdown list.
We can Enable or Disable the options in the given Combobox widget by providing the state property. The state property forces to make a widget either active or disabled. To disable the Combobox widget, we have to set the state property as readonly or disabled.
Example
#Import the required Libraries from tkinter import * from tkinter import ttk #Create an instance of Tkinter frame win = Tk() #Set the geometry of Tkinter Frame win.geometry("750x250") #Define a Label widget Label(win, text= "Select an Option from the List", font=('Aerial', 14, 'bold')).pack(pady=15) #Create a Combobox with list of items var= StringVar() my_combobox= ttk.Combobox(win, textvariable=var, values=["High", "Mid","Low"], state= 'disabled') my_combobox.pack() #Create a Button widget win.mainloop()
In the above code snippet, we have disabled the Combobox widget by disabling the state. Now, to make the widget fully functional, just change the state of the widget using state= ‘normal’.
Output
Advertisements