Although this happens to work in this example, I want to emphasize the
fact that THIS IS NOT RIGHT. This is NOT the way to write GUI applications.
All that the __init__ code in a wx application does is set up data
structures and send messages. It doesn't draw ANYTHING. The drawing
happens in response to the messages. In order for the messages to be
processed, someone has to drain the message queue and dispatch the
messages. That is the job of wxApp.MainLoop. ALL of your event
callbacks are called from wxApp.MainLoop. If this code were to create a
timer, the timer events would not fire.
Now, it just so happens that wx.Yield() makes one pass through the
message queue, so the code above happens to work, but it's still not right.
Any time you see this:
window.Show()
...
window.Destroy()
app.MainLoop()
you are seeing an incorrect application. window.Show() queues up a
"paint" message, asking the window to show itself. window.Destroy()
queues up a "destroy" message, asking the window to kill itself.
NEITHER of those messages will be processed until someone drains the
message queue, and when that actually happens, BOTH messages will be
processed at once.
window.Destroy() should always be called in an event callback, in
response to some window event that can be called from MainLoop.
ยทยทยท
On Thu, 27 Apr 2006 16:00:23 +0100, Ricardo Pedroso <ricardo.pedroso@netvisao.pt> wrote:
On Thu, 2006-04-27 at 14:42 +0200, Franz Steinhaeusler wrote:
Hi,
given this code:
import wx
import timeclass TestDialog(wx.Dialog):
def __init__(self, parent):
wx.Dialog.__init__(self, None, -1)
self.label = wx.StaticText(self, -1, "Test Static Text")app = wx.App(0)
w = TestDialog(None)
w.Show()
for i in range(3):
time.sleep(1)
#wx.Yield()
print i
w.Destroy()
app.MainLoop()The static text is not visible.
What is wrong here?Just force an Update:
(...)
for i in range(3):
w.Update()
wx.Yield()
time.sleep(1)(...)
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.