[wxPython-users] Buttons and automatic key acelerators

Simon Clay simon.clay at imperial.ac.uk
Fri Jun 16 08:41:51 PDT 2006


On Fri, Jun 16, 2006 at 01:47:51PM +0200, Oswaldo Hern?ndez wrote:
> Hi all,
> 
> To make automatic key acelerators in Windows XP y put on the labels  an '&' 
> before the accelerator letter:
> 
> 	self.label_6 = wx.StaticText(self, -1, "Press Alt + &c to get focus")
> 
> When press Alt + key the focus goes to the control. This is ok.
> 
> But with buttons when press the key the focus continues on the control.
> 
> I attach a simple dialog with demo.
> 
> Nedd the buttons any special property to get the focus when press the key?

You can make it work by writing

  self.button_3.SetFocus()

at the start of your OnBtn3() method.  More generally,

  self.FindWindowById(event.GetId()).SetFocus()

sets the focus to the control the event came from.

If you do that, alt + key acts exactly the same as a mouse click.  It
"presses the button" and gives it focus.

There may be a better way to do it, but I think this does what you want.

  Simon.





More information about the wxpython-users mailing list