Use of while(1) with app.mainLoop of wxpython

Godson Gera godson.g at gmail.com
Fri Nov 2 02:15:00 EDT 2007


On 11/2/07, tarun <tarundevnani at gmail.com> wrote:
>
> Dear All,
>
> I've have created a GUI (using wxPython widgets) where in I've a message
> log window (A TextCtrl window). I've a router.dll that helps me putting in
> message onto a channel. In my script that generates the GUI, I want to
> continuously poll the channel and populate the messages from the channel to
> the message log window.
>
> For this I've  to put a while (1) loop, but when I do this, the GUI
> doesn't come up. I see the GUI coming when while(1) is removed. Is there any
> issue with usage of app.mainloop and while(1) together.
>
> Quick help would be really appreciated.
>
>
> Hi Tarun,

The best practice to poll things in any GUI application is to use timers
provided by the GUI frameworks. All of the GUI frameworks does provide
timers, so does wxPython. Look for wx.Timer (also look for wx.CallAfter )
and use it to poll what ever the things you want

http://www.wxpython.org/docs/api/wx.Timer-class.html

When you use a while(1) loop, the python interpreter enters into an infinite
local loop thus GUI events never gets processed.  So your case seems be
that, the while loop is getting executed before GUI is drawn on screen, it
will never show up till the loop exits. And if while(1) is executed after
GUI is drawn on screen, it will hangup and will not get updated till the
loop exits. So avoid using while loops in your GUI for polling long running
tasks .

-- 
Godson Gera,
http://godson.auroinfo.com
http://godson.in

-- 
Godson Gera,
http://godson.auroinfo.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20071102/4d5d6e1e/attachment.html>


More information about the Python-list mailing list