Sanne Korzec wrote:
Hi There,
I'm writing a GUI which shows a picture in a panel. I now want to update the
image from time to time to make a crude animation. However if I do this
within the same event, it doesn't work. This code shows nothing for 1 second
and then only shows the last image.Any hints would be helpful.
CODE:
def some_handler(self, event):
self.bitmap = wx.Bitmap('pics/demo1.jpg')
wx.EVT_PAINT(self, self.OnPaint)
self.mainPanel.Layout()
time.sleep(1)
self.bitmap = wx.Bitmap('pics/demo2.jpg')
wx.EVT_PAINT(self, self.OnPaint)
self.mainPanel.Layout()def OnPaint(self,event):
dc = wx.PaintDC(self)
dc.DrawBitmap(self.bitmap, 10, 10)
Yes, you have a misunderstanding here. The wx.EVT_PAINT function does not call an event handler. All it does is change the function that will be called the next time the event occurs.
If you want to force the current window to be repainted, use
self.Refresh()
However, you might want to use a wx.Timer to do this instead of sleeping. When you sleep in an event handler, you prevent your application from handling any events during that period.
···
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.