faqts : Computers : Programming : Languages : Python : Snippets

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

4 of 4 people (100%) answered Yes
Recently 3 of 3 people (100%) answered Yes

Entry

Setting Focus in Pmw.Dialog

Nov 19th, 2008 21:43
Chris Zate, unknown unknown, Matthew Dixon Cowles


Problem:
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()
----------------------------------------------------------------------
The result of "dialog.configure( activatecommand = w.focus_set )" is 
that the dialog doesn't get focus at all.
If I comment this line out, the dialog gets focus, but the user has to 
click in the entry field, or tab twice to get to it (first tab goes to 
OK button).
Solution:
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()
http://animaux.leblogguide.com/
http://voyagesingapour.leblogguide.com
http://voyageauperou.leblogguide.com
http://voyageauchili.leblogguide.com
http://italiehotels.leblogguide.com