Hi guys
I am making a program that uses a text control to move messages from one place to another. My program needs to be able to, once the message has been moved, delete what is in the textCtrl. I can go:

self.textCtrl.SetValue('')

but that leaves me with a problem as the next time i put my cursor in the text control it is one line down. It added a whole line! So i was wondering how i would combat this so that the textctrl would be reset to have nothing in it?

Recommended Answers

All 7 Replies

Could you use EmulateKeyPress() after that to send a backspace to it?

Chris

No i dont think so.

Emulate key press required an event. I think that means somethign like wx.EVT_TEXT or something. Am i wrong? Can you use the backspace character or some kind of ascii key code?

Hmm i see your point, i cannot find a method of creating a wxKeyEvent event which is what is required for EmulateKeyPress().

Another possible solution would be to use

self.textCrtl.SetInsertionPoint(0)

Or you could use this method to clear the textcontrol which should work perfectly

self.textCtrl.Remove(0, self.textCtrl.GetLastPosition()+1)

Hope that helps

Chris

Okay both of those did not actually do anything different from my first idea. So i went with the SendKeys module and sent the backpace key once so that the cursor would be taken back to the start again.

I do have one last issue though, that is, this text that gets entered in this textCtrl gets pasted up into another, this slowly accumulates. Soon though the text starts to need a scroll bar. My problem is that the text dissapears at the end of the TextCtrl. I want to be able to auto-scroll or something like that but i cant find out how to make it automatically always scroll down to the end.

Hmm thats odd. I did think about the SendKeys module but i wasn't sure if you wanted to use it or not.

Addressing your other issue, did you try using self.textCtrl2.SetInsertionPoint(self.textCtrl2.GetLastPosition()+1) , i cannot say as i've tried it but that should theoretically force it to scroll to the bottom.

Chris

commented: Thanks for that +1

Yep, that works a charm. I tried something simillar before but it didnt work. Oh well, that all works now, thanks Chris!

Yep, that works a charm. I tried something simillar before but it didnt work. Oh well, that all works now, thanks Chris!

Hehe glad you got it working.

To think i've only ever downloaded wxPython & created a basic window with a listbox on it. I've never even added data to that list box hehe. Ah well it's all good fun.

P.S Mark as solved xD

Chris

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.