My aim is to update the same Label object every time the drop-down list selection changes. From what I know, because of closure, the outer environment object, lblResult must be available to the event handler function locationChanged(). But in the handler, lblResult is always None. I tried passing the lblResult object to the handler, declaring lblResult in event handler global, but none worked. If anyone can explain why it's so, how can I fix it, it will be a great help. Thanks.
from tkinter import Label, OptionMenu, StringVar, Tk
root = Tk()
def locationChanged(x):
lblResult.config(text=x) # lblResult is None always
#lblResult = Label(root, text=x).pack() # this works but I want the same Label to be updated
locations=["Select a City...", "Amsterdam,NL", "NewYork,NY,US", "Sydney,NSW,AU", "Toronto,ON,CA"]
selectedLocation = StringVar()
ddlLocation = OptionMenu(root, selectedLocation, *locations, command=lambda x: locationChanged(x)).pack()
lblResult = Label(root, text="").pack()
root.mainloop()