Frage

I am trying to remove the very last character from a TextCtrl object in wxPython. I'm using wxPython 2.8.12 and Python 2.7.2.

My code is as follows:

def btnBkClicked(self, e):
    self.txtItem.Remove(self, (self.txtItem.GetLastPosition()[-1]), (self.txtItem.GetLastPosition()))

However, that doesn't work :( What do I need to change/do?

War es hilfreich?

Lösung

If you need to remove the very last character from the string, try

self.txtItem.SetValue(self.txtItem.GetValue()[:-1]) 

This code gets current text from TextCtrl and sets and sets its value to this text up to the last symbol.

Regarding your input, TextCtrl.Remove needs two parameters: from and to, which are integer numbers giving the first and the last positions to be removed. As GetLastPosition returns the number of characters in the control, your code should be modified as

self.txtItem.Remove(self.txtItem.GetLastPosition()-1, self.txtItem.GetLastPosition())
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top