In the example below the variable 'food' gets printed when the button OK is clicked. I need to eliminate this OK button, therefor I would like the 'food' variable to be printed upon selecting it in the drop down menu. Can someone show me how I can get this result please? Please make the answer clear and simple since I am a beginner with tkinter.
from Tkinter import *
import ttk
Root = Tk()
var = StringVar(Root)
var.set("apple") # initial value
option = ttk.Combobox(Root, textvariable=var, values=["apple", "carrot", "orange"])
option.pack()
def ok():
food = var.get()
print(food)
button = Button(Root, text="OK", command=ok)
button.pack()
mainloop()