Problem with TextCtrl not displaying the entire text

Hello everyone,

I have the following code which creates a window with a text control, and sets the value of the text control to a 26 character string (“abcdefghijklmnopqrstuvwxyz”). The problem I have is that when I run the program it displays a portion of the string (“ijklmnopqrstuvwxyz”), and I expect it to display the entire string. The entire string is in the text control (I can see it all by pressing the Home key while the text control has focus), but for some reason it is not initially displaying all of it.

Can somebody help me out and tell me what I need to do in order to get this to work?

Thanks in advance.

···

import wx

class MainWindow(wx.Frame):
def init(self, parent,id, title):
wx.Frame.init (self, parent, -1, title, size=(300, 120))
self.panel = wx.Panel(self, wx.ID_ANY)

    box = wx.BoxSizer(wx.VERTICAL)

    self.text1 = wx.TextCtrl(self.panel, -1)

    box.Add(self.text1, 0, wx.EXPAND)

    self.panel.SetSizer(box)

    self.text1.SetValue("abcdefghijklmnopqrstuvwxyz")

    self.Show(True)

app = wx.PySimpleApp()
frame = MainWindow(None, -1, “Test”)
app.MainLoop()

@Steven - Thanks, that seems to work. Though it seems strange to me though that my original code doesn’t work - I wish I knew whether it is due to a bug in wxWidgets or just because I am misunderstanding something.

mercado mercado wrote:

Hello everyone,

I have the following code which creates a window with a text control, and sets the value of the text control to a 26 character string ("abcdefghijklmnopqrstuvwxyz"). The problem I have is that when I run the program it displays a portion of the string ("ijklmnopqrstuvwxyz"), and I expect it to display the entire string. The entire string is in the text control (I can see it all by pressing the Home key while the text control has focus), but for some reason it is not initially displaying all of it.

Can somebody help me out and tell me what I need to do in order to get this to work?

This is a known problem with the native widget on Windows. You can workaround it by resetting the insertion point to the beginning of the widget, or doing something else that will cause the native widget to reset itself.

For example, the TextCtrl sample in the demo does this:

         wx.CallAfter(t1.SetInsertionPoint, 0)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!