How to set a wx.textctrl can editable or readonly?

Frank Millman frank at
Thu Jan 19 05:57:08 CET 2006

Tim Chase wrote:
> >     def onGotFocus(self,evt):
> >         if readonly:
> >             self.Navigate()
> >
> > This causes the control to react as if the user press 'tab'. By default
> > it always tabs forwards, but it takes an optional 'IsForward' argument
> > - set it to False to tab backwards.
> Just a pedantic query, not having wx under my fingertips at the
> moment...what happens if you three controls, A (r/w), B
> (read-only), and C (r/w) in that focus order...if use shift+tab
> in control C, does it properly go back to A, or does it move you
> forward again to control C.
You have to control it yourself, but wx gives you the tools to do so.
You can register an event handler at panel level called
wx.EVT_NAVIGATION_KEY It is triggered each time tab or shift-tab is
pressed, and has a method called GetDirection(), which returns True for
forwards (i.e. tab) and False for backwards (i.e. shift-tab). You can
use this to maintain a 'direction' attribute, which you can pass as an
argument to self.Navigate(). It will then always navigate in the
correct direction.

> Additionally, you should be able to copy text from a read-only
> control, so ousting the focus may not be quite the right thing to do.
Good point. Alternative approaches would be to trap EVT_KEY_DOWN or
EVT_TEXT to detect and block attempts to modify the contents of the


More information about the Python-list mailing list