Simple ttk ComboBox demo Simple ttk ComboBox demo tkinter tkinter

Simple ttk ComboBox demo


Just bind the virtual event <<ComboboxSelected>> to the Combobox widget:

class App:    def __init__(self, parent):        self.parent = parent        self.value_of_combo = 'X'        self.combo()    def newselection(self, event):        self.value_of_combo = self.box.get()        print(self.value_of_combo)    def combo(self):        self.box_value = StringVar()        self.box = ttk.Combobox(self.parent, textvariable=self.box_value)        self.box.bind("<<ComboboxSelected>>", self.newselection)        # ...


In the more general case, if you need to get the value of a Variable when it is updated, it would be advisable to use the tracing facility built into them.

var = StringVar()  # create a var object# define the callbackdef tracer(name, idontknow, mode):    # I cannot find the arguments sent to the callback documented    # anywhere, or how to really use them.  I simply ignore    # the arguments, and use the invocation of the callback    # as the only api to tracing    print var.get()var.trace('w', tracer)# 'w' in this case, is the 'mode', one of 'r'# for reading and 'w' for writingvar.set('Foo')  # manually update the var...# 'Foo' is printed