Optionmenu.

T

Thor

I have the following function (with some things removed):

def add_stock():
stockw=Tk()
stockw.title("New stock solution")
sofl=Frame(stockw)
sofl.pack()
u=StringVar()
u.set("M")
cw=OptionMenu(sofl,u,"M","m","u","v","w")
cw.grid(row=1,column=2)

but the widget keeps not showing teh selected option. If I fo the same out
of the function it works without problem (with stockw.mainloop()). What am
I missing? Anybody can point me out to the solution/the right webpage?
 
T

Thor

Michael said:
Yes of course that's it! I posted same advice some days ago. I overlooked
it because it - strangely - worked on my machine. But there seems to be
different behaviour with Tk 8.3 and 8.4
Thanks. I'll check it today. The purpose was to make a windowd with 2 packed
frams, one qith 'things, and the other with the typical OK-Cancel buttons,
and then into the first one, put the widgets in a grid. I'll try to redo it
all using just one.

About teh u var, actually it is a global one...:D
 
M

Michael Peuser

Thor said:
I have the following function (with some things removed):

def add_stock():
stockw=Tk()
stockw.title("New stock solution")
sofl=Frame(stockw)
sofl.pack()
u=StringVar()
u.set("M")
cw=OptionMenu(sofl,u,"M","m","u","v","w")
cw.grid(row=1,column=2)

but the widget keeps not showing teh selected option. If I fo the same out
of the function it works without problem (with stockw.mainloop()). What am
I missing? Anybody can point me out to the solution/the right webpage?
--

Works fine with Python 2.2 Tk8.3.
Though it's looks a little bit funny that you initialize Tk inside the
function and that you use a local variable u for your your interface...


Kindly
Michael P
 
K

klappnase

Thor said:
I have the following function (with some things removed):

def add_stock():
stockw=Tk()
stockw.title("New stock solution")
sofl=Frame(stockw)
sofl.pack()
u=StringVar()
u.set("M")
cw=OptionMenu(sofl,u,"M","m","u","v","w")
cw.grid(row=1,column=2)

but the widget keeps not showing teh selected option. If I fo the same out
of the function it works without problem (with stockw.mainloop()). What am
I missing? Anybody can point me out to the solution/the right webpage?

Hi,

I'm not sure if that is your problem here, but I think you should not use pack()
and grid() inside the same window, otherwise strange things might happen.
Maybe with sofl.grid() it will work.

Michael
 
M

Michael Peuser

Thor said:
Thanks. I'll check it today. The purpose was to make a windowd with 2 packed
frams, one qith 'things, and the other with the typical OK-Cancel buttons,
and then into the first one, put the widgets in a grid. I'll try to redo it
all using just one.
You can use Frames. The rule is: Only one kind of geometry manager per
frame.

Kindly
Michael P
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top