I have a Tkinter list box populated with city names. I want to grab the selected value and pass it to subsequent code after the mainloop. I have the following tkinker code:
master = tk.Tk()
variable = StringVar(master)
variable.set(cities_list[0]) # default value
w = OptionMenu(master, variable, *cities_list)
w.pack()
def ok():
print ("value is:" + variable.get())
return variable.get()
window.destroy()
button = Button(master, text="OK", command=ok)
button.pack()
mainloop()
v_list = variable.get().split('-')
The button is stuck in a loop and will not close. I want to close the button after a selection. I've tried both "window.destroy()" and "master.destroy()"
What am I doing wrong?