Textctrl: Selecting text doesn't work

I want to have the user enter text into a multi-line Textctrl and then
when a button is pressed have that text selected. But for some reason
SelectAll() doesn't work. An excerpt to illustrate.

    def __init__(self):
        self.textBox = wx.TextCtrl(panel, -1, style=wx.TE_MULTILINE |
wx.TE_DONTWRAP)

    def OnButtonPressed(self, event):
        self.textBox.SelectAll()

Interestingly though, the following *does* work:

    def __init__(self):
        self.textBox = wx.TextCtrl(panel, -1, style=wx.TE_MULTILINE |
wx.TE_DONTWRAP)
        self.textBox.SetValue("A test string")
        self.textBox.SelectAll()

Is there an extra step to make the former work. I've already try the
CallAfter() function... didn't work.

Thanks!

Yony wrote:

I want to have the user enter text into a multi-line Textctrl and then
when a button is pressed have that text selected. But for some reason
SelectAll() doesn't work. An excerpt to illustrate.

    def __init__(self):
        self.textBox = wx.TextCtrl(panel, -1, style=wx.TE_MULTILINE |
wx.TE_DONTWRAP)

    def OnButtonPressed(self, event):
        self.textBox.SelectAll()

Interestingly though, the following *does* work:

    def __init__(self):
        self.textBox = wx.TextCtrl(panel, -1, style=wx.TE_MULTILINE |
wx.TE_DONTWRAP)
        self.textBox.SetValue("A test string")
        self.textBox.SelectAll()

Is there an extra step to make the former work. I've already try the
CallAfter() function... didn't work.

Platform and version? If you're on windows then the textctrl only shows the selection when the widget has the focus. Since you are setting the selection in the button handler then they button has the focus at that time.

···

--
Robin Dunn
Software Craftsman

Try to set focus to the control before selecting:

self.textBox.SetFocus()

···

--
Regards,
Alex Karson

On Jul 11, 11:11 am, Yony <yones...@gmail.com> wrote:

I want to have the user enter text into a multi-line Textctrl and then
when a button is pressed have that text selected. But for some reason
SelectAll() doesn't work. An excerpt to illustrate.

def \_\_init\_\_\(self\):
    self\.textBox = wx\.TextCtrl\(panel, \-1, style=wx\.TE\_MULTILINE |

wx.TE_DONTWRAP)

def OnButtonPressed\(self, event\):
    self\.textBox\.SelectAll\(\)

Interestingly though, the following *does* work:

def \_\_init\_\_\(self\):
    self\.textBox = wx\.TextCtrl\(panel, \-1, style=wx\.TE\_MULTILINE |

wx.TE_DONTWRAP)
self.textBox.SetValue("A test string")
self.textBox.SelectAll()

Is there an extra step to make the former work. I've already try the
CallAfter() function... didn't work.

Thanks!