How do I change the text without user input

In addition to changing the text of the display based on user input, wx.TextCtrl provides a number of methods that change the text in the display from within your program. You can change the text outright, or just move the insertion point to a different place in the text. Table 7.4 lists the text manipulation methods of wx.TextCtrl.

Table 7.4 Text manipulation methods of wx.TextCtrl




Appends the text argument to the end of the text in the control. The insertion point also moves to the end of the control.


Resets the text value of the control to "". Also generates a text updated event.


Given a keypress event, inserts into the control the character associated with the event, just as if the actual keypress had occured.




The position is the integer index of the current insertion point, or to put it another way, the index where the next inserted character would be placed. The beginning of the control is 0.

GetRange(from, to)

Returns the string between the given integer positions of the control.

GetSelection() GetStringSelection() SetSelection(from, to)

GetSelection() returns a tuple (start, end) with the indexes of the currently selected text. GetStringSelection() returns the string contents of that range. The setter takes the integer endpoints of the range.

GetValue() SetValue(value)

SetValue() changes the entire value of the control. The getter returns the entire string.

Remove(from, to)

Removes the given range from the text.

Replace(from, to, value)

Replaces the given range with new value. This can change the length of the text.


Similar to AppendText() except that the new text is placed at the current insertion point.

These methods are particularly useful when you have a read-only control, or if you want the text in the control to change based on events other than a user key press.

Was this article helpful?

0 0

Post a comment