Ernest Poldrige
Ernest Poldrige

Reputation: 429

wxPython writing to disabled wx.TextCtrl

for a pet project of mine I am using a wxPython 2.8 and I have a dialog with a disabled wx.TextCtrl:

self.txt = wx.TextCtrl(self, wx.ID_ANY, size=(450,100),
                          style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)

in the same dialog there is a button; when button is clicked I want to append some text (programmatically) to the TextCtrl. I tried by using

self.txt.AppendText('Hello')

but it doesn't work (Windows XP OS).

Is there any way to do that ?

thanks

Upvotes: 1

Views: 455

Answers (1)

Rolf of Saxony
Rolf of Saxony

Reputation: 22443

You can use the wx.TextCtrl write function to achieve that.

import wx

class MainFrame(wx.Frame):

    def __init__(self):
        wx.Frame.__init__(self, None, title='Test TextCtrl')
        self.panel = wx.Panel(self)
        self.text1 = wx.TextCtrl(self.panel,value="My Text",pos=(10,10),size=(350,30))
        self.button = wx.Button(self.panel, -1, "Click",pos=(10,40))
        self.button.Bind(wx.EVT_BUTTON, self.On_Button)
        self.text1.Enable(False)
        self.Show()

    def On_Button(self, event):
        self.text1.write(" Click ")

if __name__ == '__main__':
    app = wx.App()
    frame = MainFrame()
    app.MainLoop()

Upvotes: 2

Related Questions