Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get text when enter is pressed in a text box in wxPython

I have a (single line) TextCtrl. The user types data into this. When they press enter, the contents of the box need to be extracted so they can be processed. I can't figure out how to catch enter being pressed.

According to the docs, with the style wx.TE_PROCESS_ENTER set on my TextCtrl, it should generate a wx.EVT_COMMAND_TEXT_ENTER event when enter is pressed in the box, which I could then catch. However, wx.EVT_COMMAND_TEXT_ENTER seems not to exist (I get "module has no attribute EVT_COMMAND_TEXT_ENTER), so I'm a bit stuck. Googling just gets a couple of hits of people complaining wx.EVT_COMMAND_TEXT_ENTER doesn't work, so I guess I need another way of doing it.

like image 312
Sam Avatar asked Apr 27 '10 21:04

Sam


2 Answers

I've never seen wx.EVT_COMMAND_TEXT_ENTER. I have used wx.EVT_TEXT_ENTER though...

like image 135
Ignacio Vazquez-Abrams Avatar answered Oct 04 '22 15:10

Ignacio Vazquez-Abrams


Use style = wx.TE_PROCESS_ENTER in TextCtrl and Bind with Event wx.EVT_TEXT_ENTER

self.Text_Enter = wx.TextCtrl(self , 2 ,style = wx.TE_PROCESS_ENTER, size =(125,150), pos = (170,0))

self.Text_Enter.SetForegroundColour(wx.RED)

self.Bind(wx.EVT_TEXT_ENTER, self.Txt_Ent, id = 2)
def Txt_Ent(self,event):
   msg1 = (str(self.Text_Enter.GetValue()))
   wx.MessageBox(msg1)
like image 37
user8504400 Avatar answered Oct 04 '22 15:10

user8504400