[Tutor] Pmw/Tkinter question

boB Stepp robertvstepp at gmail.com
Sun Mar 13 20:19:55 EDT 2016


I just cannot leave this problem alone; however, I *do* believe I have
found the correct way to do what Albert-Jan desires within the
publicly accessible features of Pmw and Tkinter.  I looked at the Pmw
documentation online at

http://pmw.sourceforge.net/doc/OptionMenu.html

and it said:

<quote>
menubutton

The menu button displaying the currently selected value. By default,
this component is a Tkinter.Menubutton.
</quote>

So I looked up Tkinter.Menubutton next in one of my books and it has
the desired anchor option.  So if we add

 menubutton_anchor = 'w'

in the appropriate place, then I get the desired alignment.  BTW, this
fits in with Peter's suggestion.  It just needs to be using the normal
Pmw/Tkinter machinery:

On Sat, Mar 12, 2016 at 2:17 AM, Albert-Jan Roskam
<sjeik_appie at hotmail.com> wrote:

> # -*- coding: utf-8 -*-
>
> import Tkinter
> import Pmw
>
> class Demo:
>     def __init__(self, parent):
>         # Create and pack the OptionMenu megawidgets.
>         # The first one has a textvariable.
>         self.var = Tkinter.StringVar()
>         self.var.set('steamed')
>         self.method_menu = Pmw.OptionMenu(parent,
>                 labelpos = 'w',
>                 label_text = 'Choose method:',
>                 menubutton_textvariable = self.var,
>                 items = ['baked', 'steamed', 'stir fried', 'boiled', 'raw'],
>                 menubutton_width = 10,
>         )
>         #self.method_menu.pack(anchor = 'w', padx = 10, pady = 10)
>         self.method_menu.grid(row=0, column=0, sticky = 'w', padx = 10, pady = 10)
>
>         self.vege_menu = Pmw.OptionMenu (parent,
>                 labelpos = 'w',
>                 label_text = 'Choose vegetable:',
>                 items = ('broccoli-broccoli-broccoli-broccoli', 'peas', 'carrots', 'pumpkin'),
>                 menubutton_width = 10,
                  menubutton_anchor = 'w',
>                 command = self._printOrder,
>         )
>         #self.vege_menu.pack(anchor = 'w', padx = 10, pady = 10)
>         self.vege_menu.grid(row=1, column=0, sticky = 'w', padx = 10, pady = 10)
[...]

Probably "menubutton_anchor = 'w'" should be added to the other two
menu buttons' code as they in the future might have overly long item
names.

And thanks, Oscar!  That makes me feel quite a bit better as I wash
the egg off my face from my earlier erroneous efforts.  I think I have
it right now.

boB


More information about the Tutor mailing list