Setting Focus in Pmw.Dialog

Matthew Dixon Cowles matt at mondoinfo.com
Tue Sep 19 01:32:39 EDT 2000


On Tue, 19 Sep 2000 16:07:40 +1000, Yael Raz <yaelr at locus.com.au>
wrote:

>A small but annoying problem with my first Python project:

>I use Pmw.Dialog to prompt the user for some text.  The dialog is
>just what I need, but for some reason I can't set the initial
>keyboard focus to the entry field.

>The standard "askstring" dialog doesn't give me control over the edit
>field size (that I can see), so I tried this:

> dialog = Pmw.Dialog( root,
>       buttons = ( 'OK', ),
>       buttonboxpos = S,
>       title = 'Prompt' )
>
> w = Pmw.EntryField( dialog.interior(), label_text = prompt,
>   labelpos = NW,labelmargin = 1, entry_width = 50 )
> w.pack( padx = 15, pady = 15 )
>
> dialog.configure( activatecommand = w.focus_set )
> dialog.focus_force()
>
> dialog.activate()

Yael,
Your problem is that a Pmw.EntryField is itself a compound widget
(I've been caught by this one too). You want something like:

dialog.configure( activatecommand = w.component("entry").focus_set )

You can also get a similar result by replacing

dialog.configure( activatecommand = w.focus_set )
dialog.focus_force()

with

w.component("entry").focus_force()

Regards,
Matt



More information about the Python-list mailing list