Thank you very much. It seems it works. How ever, if I don't
use a
command=lambda... in the add_command I cannot get the
OptionMenu value
changed (see below). Is it really necessary all the
lambda... function I
am doing or there is a smarter way of doing the job?
Regards
Vasillis
--------
from Tkinter import *
values = ["one","two","three"]
root = Tk()
var = StringVar()
var.set(values[0])
# set initial options
o = OptionMenu(root,var,*values)
o.pack()
# change options
m = o.children['menu']
m.delete(0,END)
newvalues = "a b c d e f".split()
for val in newvalues:
m.add_command(label=val,command=lambda
v=var,l=val:v.set(l))
var.set(newvalues[0])
root.mainloop()
---------
mkieverpy tlink.de wrote:
> Vasilis Vlachoudis wrote:
>
>>
values=["One","Two","Three"]
# Initial list
>> o = OptionMenu(frame, *values)
>> #...
>> #then later in the code read new values from a file
>> newvalues = f.readline().split()
>> o.config(???=newvalues)
>>
>>
> With
> m = o.children ['menu']
> you can access the menu which implements the
OptionMenu.
> OptionMenu uses 'command' entries.
> So you can add new entries with
>
m.add_command(label='a_new_entry',command=if_you_need_to_set
_a_var_or_something)
> I never used this personally.
> Hope it works for you.
>
> Matthias Kievernagel
> mkiever at web dot de
>
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
a>
>
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss
a>
|