[Tutor] Pmw/Tkinter question

Peter Otten __peter__ at web.de
Sat Mar 12 04:28:36 EST 2016


Albert-Jan Roskam wrote:

> Hello,
> 
> Below is a slightly modified example about Pmw/Tkinter from
> http://pmw.sourceforge.net/doc/howtouse.html. I changed the geometry
> manager from 'pack' to 'grid', because I use that in all other parts of my
> program. The problem is, 'broccoli' won't display nicely under vege_menu.
> I want it to left-align, not center (I don't case that it's truncated). In
> plain Tkinter I could do "self.vege_menu.configure(anchor=Tkinter.W)" but
> this raises a KeyError in Pmw.

I don't see an official way to to change the alignment, but looking into the 
source there's

class OptionMenu(Pmw.MegaWidget):

    def __init__(self, parent = None, **kw):

[...]
	self._menubutton = self.createcomponent('menubutton',
		(), None,
		Tkinter.Menubutton, (interior,),
		borderwidth = 2,
		indicatoron = 1,
		relief = 'raised',
		anchor = 'c',
		highlightthickness = 2,
		direction = 'flush',
                takefocus = 1,
	)

so if you don't mind touching _private attributes

>         self.vege_menu = Pmw.OptionMenu (parent,
>                 labelpos = 'w',
>                 label_text = 'Choose vegetable:',
>                 items = ('broccoli-broccoli-broccoli-broccoli', 'peas',
>                 'carrots', 'pumpkin'), menubutton_width = 10,
>                 command = self._printOrder,
>         )
          self.vege_menu._menubutton.config(anchor=Tkinter.W)

>         #self.vege_menu.pack(anchor = 'w', padx = 10, pady = 10)
>         self.vege_menu.grid(row=1, column=0, sticky = 'w', padx = 10, pady
>         = 10)

should work.



More information about the Tutor mailing list