Months=Ĭb1 = ttk.Combobox(my_w, values=months,width=7)ī1=tk.Button(my_w,text="set('Apr')", command=lambda: my_upd1()) The output of cb1.current() is an integer so we used str() to convert the same to string before adding. Here on click of the button b1 the value of the Combobox cb1 is set to Apr then this value and index is collected and displayed in the Label l1 To get the index of the selected option we can use cb1.current() Example To get the selected value ( option ) we can use cb1.get() Getting value and index of selected option We can use the index of the option cb1.current(2) to set it as default selection. Months= # optionsĬb1 = ttk.Combobox(my_w, values=months,width=7) # ComboboxĬb1.grid(row=1,column=1,padx=10,pady=20) # adding to gridīy using cb1.set('Apr') we are setting a default selected option for the Combobox. My_w.geometry("300x150") # Size of the window Tkinter Combobox to select Option or add data by user & reading adding and setting default options
0 Comments
Leave a Reply. |