Tkinter Bind Combobox
When the options in Combobox change, a virtual <<ComboboxSelected>>
event will be generated, and you can also use this feature to bind this event to a handler.
Example#1
Synchronize the contents of Combobox and Label.
# from tkinter import *
from tkinter.ttk import *
from tkinter import *
# Note the order of these two introductory statements; reversing them will make a difference
# The parameters of tkinter.label and tkinter.ttk.label are different, and the bg and background will be different
def comboSelection(event): # Print the results of the selection
labelVar.set(var.get()) # Synchronize Label content
root = Tk()
root.title("apidemos.com")
root.geometry("300x120")
var = StringVar()
cb = Combobox(root,textvariable=var) # Create Combobox
cb["value"] = ("Python","Java","C#","C","C++") # Set option content
cb.current(0)
cb.bind("<<ComboboxSelected>>",comboSelection) # Binding
cb.pack(side=LEFT,padx=10,pady=10)
print("var: ",var.get())
labelVar = StringVar()
label = Label(root,bg="yellow",textvariable=labelVar)
labelVar.set(var.get())
label.pack(side=LEFT)
root.mainloop()
Output: