[wxPython-users] need help displaying One Word at a time...

Robin Dunn robin at alldunn.com
Tue Mar 4 12:53:19 PST 2008


Gary Kline wrote:
> Hi Guys,
> 
> Well, by trial/error, I'm learning....  what works and what doesn't;
> and what's necessary and not.   But I'm stuck wx. StaticText in a loop.
> I've got a two-word file: "Hello, world" and want to disply each for a
> fraction of a sec.  
> 
> 
> 
> 
>     def __init__(self, parent, log):
>         wx.Panel.__init__(self, parent, -1)
>         self.log = log
> 
>         f = open("2w.txt", "r")
>         lines = f.readlines()
> 
>         l1 = wx.StaticText(self, -1, "wx.TextCtrl")
>         for line in lines:
>             print "DEBUG: line = %s" % (line);
>             words = string.split(line)
>             for word in words:
>                 print "DEBUG: word = %s" % (word);
>                 t1 = wx.TextCtrl(self, -1, word);
>                 time.sleep(0.99)
>                 wx.CallAfter(t1.SetInsertionPoint, 0)
>                 self.tc1 = t1
>             space = 4
>             sizer = wx.FlexGridSizer(cols=1, hgap=space, vgap=space)
>             sizer.AddMany([ l1, t1, (0,0), ])
>             border = wx.BoxSizer(wx.VERTICAL)
>             self.SetSizer(border)
>             self.SetAutoLayout(True)
> 
>         f.close()
> 
> 
> I probably have some unnecessary code in here; but then this is my 
> first attempt at python+X11.  I've googled and grep'd around to see
> if there are any other wx python text function I could try.  Thought 
> I'd ask the wizards first:)

Keep in mind that in the __init__ method the window most likely is not 
even visible yet (because the parent frame probably isn't shown yet) so 
sleeping and changing values there will not be able to be seen at all. 
Secondly, you should not us sleep for timing things like this, use a 
timer and events instead.  In other words, give the widget your initial 
value, create and start a timer and bind a handler to the timer event, 
and then continue with the normal startup.  Then in the timer event 
handler you can just change the value of the widget.

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





More information about the wxpython-users mailing list