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 example below, I need the value of value_of_combo
variable to be updated automatically every time a new selection is made.
from Tkinter import *
import ttk
class App:
value_of_combo = 'X'
def __init__(self, parent):
self.parent = parent
self.combo()
def combo(self):
self.box_value = StringVar()
self.box = ttk.Combobox(self.parent, textvariable=self.box_value)
self.box['values'] = ('X', 'Y', 'Z')
self.box.current(0)
self.box.grid(column=0, row=0)
if __name__ == '__main__':
root = Tk()
app = App(root)
root.mainloop()
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…