A newbie question about wx.PaintEvent

Hi, all.

when I run the following codes, the result is not what I expected:

···

import wx

class PaintEventFrame(wx.Frame):
def init(self,parent,id,title):
wx.Frame.init(self,parent,id,title)
self.panel=wx.Panel(self,-1)

    self.count=0
   
    self.panel.Bind(wx.EVT_PAINT,self.OnPaint)
   
    self.Center()
    self.Show(True)

def OnPaint(self,event):
    self.count=self.count+1

&nbs
p; print self.count

if name==“main”:
app=wx.App(False)
PaintEventFrame(None,-1,“PaintEvent Frame”)
app.MainLoop()

The printed result is incrementd from 1 to larger numbers continuously, why?

But if I palce “dc=wx.PaintDC(self.panel)” into the “OnPaint” method, the result is what I expected, why?

Best regards!

—I love Python!—
—ilovepython1978—


Windows Live Writer,支持离线撰写博客内容,随时随地想写就写。 立即使用!

OnPaint needs a device context created which binds the frame class and the device together. If this isn’t present, the OnPaint() function gets stuck in an infinite loop and never returns control to the frame. You must create a device context to draw on within each paint event function.

-M

···

From: ilovepython1978@hotmail.com
To: wxpython-users@lists.wxwidgets.org
Date: Sat, 10 May 2008 22:28:50 +0800
Subject: [wxpython-users] A newbie question about wx.PaintEvent

Hi, all.

when I run the following codes, the result is not what I expected:

import wx

class PaintEventFrame(wx.Frame):
def init(self,parent,id,title):
wx.Frame.init(self,parent,id,title)
self.panel=wx.Panel(self,-1)

    self.count=0
   
    self.panel.Bind(wx.EVT_PAINT,self.OnPaint)
   
    self.Center()
    self.Show(True)

def OnPaint(self,event):
    self.count=self.count+1

&nbs p; print self.count

if name==“main”:
app=wx.App(False)
PaintEventFrame(None,-1,“PaintEvent Frame”)
app.MainLoop()

The printed result is incrementd from 1 to larger numbers continuously, why?

But if I palce “dc=wx.PaintDC(self.panel)” into the “OnPaint” method, the result is what I expected, why?

Best regards!

—I love Python!—
—ilovepython1978—


Windows Live Writer,支持离线撰写博客内容,随时随地想写就写。 立即使用!


Get Free (PRODUCT) RED™ Emoticons, Winks and Display Pics. Check it out!