Simple ttk ComboBox demo

后端 未结 2 827
甜味超标
甜味超标 2020-12-08 23:31

This should be very simple but I am really struggling to get it right. All I need is a simple ttk ComboBox which updates a variable on change of selection.

In the ex

2条回答
  •  时光说笑
    2020-12-08 23:55

    Just bind the virtual event <> 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("<>", self.newselection)
            # ...
    

提交回复
热议问题