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

Frank Millman frank at chagford.com
Wed Jan 18 09:32:55 EST 2006


Hako wrote:
> Hello All,
>
>
> I have  a function to set readonly or editable of a textctrl. I'd like
> to make the textctrl initial set readonly and use other event funciton
> to set editable of the textctrl but it always can editable. How to set
> a textctrl can editable or readonly?
>

Here is one way.

Create a subclass of wx.TextCtrl, with an attribute called 'readonly'.
Set the attribute to True or False to represent the desired state.

In the subclass, create a wx.EVT_SET_FOCUS handler to be called
whenever the text control receives focus. Then do something like this -

    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.

HTH

Frank Millman

ps You will get a better response to questions like this if you post
them to the wxPython mailing list - wxPython-users at lists.wxwidgets.org




More information about the Python-list mailing list