How to change the labels of the choices in an option menu? How to change the labels of the choices in an option menu? tkinter tkinter

How to change the labels of the choices in an option menu?


If I fully understood what you are asking for then
Yes I think dictionary can be used here but as you said you want the contents of choices not to be disturbed then you can find this useful..

import Tkinter as tkdef select():    title=var.get()    print "selected string :"+title    print "corresponing integer value :"+str(choices[Dic[title]])choices = [1,2,3]Dic={'title 1':0,'title 2':1,'title 3':2}GUI = tk.Tk()var = tk.StringVar(GUI)var.set('title 1')op=tk.OptionMenu(GUI, var, *Dic.keys())op.pack(side='left',padx=20,pady=10)bt=tk.Button(GUI,text='check value',command=select)bt.pack(side='left',padx=20,pady=10)GUI.mainloop()

The indexing is quite messy but may be its exactly the way you want it
Also you can make dictionary of any length(same as of choices) using trivial loops that's too obvious :)