Tkinter Combobox to select Option or add data by user & reading adding and setting default options

plus2net
plus2net
15.9 هزار بار بازدید - 3 سال پیش - Tkinter Combobox
Tkinter Combobox options taken from M...      Part II Options from JSon , CSV , MySQL or SQLite database table :
Tkinter two interlinked Comboboxes wh... Part III Two interlinked dropdown list


Tkinter Combobox widget is a part of ttk module so we must import this to use Combobox. By using combobox user can select one of the available options or can add data which is not available as options.
The values option takes a list or tuple to create the choice to be shown to the user for selection. To get the selected option we can use get() method. By using current() method we can get the index of the selected option. To use this index as string we have to use str() function.  We can select any option by using set() method.
By using set method we can clear the selected option. By using delete method we can also remove r the selection.  
#cb1.set('') # Clear the selection
cb1.delete(0,'end') # clear the selection
By using string variable we can assign it to the Combobox by using textvariable option. Once the string variable is connected to Combobox, any change it its value can trigger the function to read and display the selected option.
We can add option to Cobbobox by using one entry box and a button. On click of the button the data entered in the entry box will be added as option of the Combobox.  Here click event of the button will execute the function my_insert() inside which we will read the data of entry box by using get()  and add the option. To prevent adding of duplicate options we can check the options if any value is already available by using if condition check.
if e1.get() not in cb1['values']:
       cb1['values'] +=(e1.get(),)

https://www.plus2net.com/python/tkint...

To get numeric value from selected option of  Combobox watch this
Tkinter Combobox returning  numeric k...

#tkinter #PythonGUI #combobox #optionsCombobox #addingOptions #python #plus2net  #GUI #defaultoption
3 سال پیش در تاریخ 1400/05/30 منتشر شده است.
15,925 بـار بازدید شده
... بیشتر