drfrev
drfrev

Reputation: 35

wxpython textctrl doesn't write when bound

I have been working on a simple textctrl project to get more acquainted with wxpython and I have hit a small road block. I am making a simple code editor, and I am currently working on the syntax highlighting. Everything works fine except because I have my textctrl bound to an event:

self.status_area.Bind(wx.EVT_CHAR, self.onKeyPress)

and I have code in that definition:

def onKeyPress (self, event):
    Line = self.status_area.GetValue()

It will no longer allow the user to type in any letters. I am able to delete and create a new line without any problem, but if I type "hello" nothing will show up. When debugging my code I know its running through onKeyPress() and the code inside and if I change the code to:

def onKeyPress (self, event):
    event.Skip()

it will work fine. I tried to recode the normal text editor workings into the onKeyPress() but it began to get too bulky. Any help on the matter would be greatly appreciated.

Upvotes: 1

Views: 1182

Answers (2)

user2229472
user2229472

Reputation: 509

to creat textctrl

self.text_ctrl = wx.TextCtrl(self.panel_1, -1, "some thing", style=wx.TE_MULTILINE | wx.TE_RICH2 )

to bind

self.Bind(wx.EVT_TEXT, self.ON_Write, self.text_ctrl)

now the definition:

def ON_Write(self, event):
   line = self.text_ctrl.Value

Upvotes: 2

chow
chow

Reputation: 484

Try EVT_TEXT rather than EVT_CHAR. In my solution, I added it AFTER event.Skip()

Upvotes: 2

Related Questions