[wxPython-users] OnPaint

Christopher Barker Chris.Barker at noaa.gov
Wed Oct 11 12:39:35 PDT 2006


Andrea Gavana wrote:
> You are binding the Paint event to the frame, so why are you calling:
> 
>>        dc = wx.PaintDC(self.panel)
> 
> On the panel?

Which is why this structure is not recommended. I think the PrepareDC() 
call in only required for ScrolledWindows, etc.

A style like the bow will make for more reusable code, and less 
confusion and errors. see item (7) in:

http://wiki.wxpython.org/index.cgi/wxPython_Style_Guide


#!/usr/bin/env python
import wx

class OnPaintPanel(wx.Panel):

    def __init__(self,*args, **kwargs):
        wx.Panel.__init__(self,*args, **kwargs)

        self.Bind(wx.EVT_PAINT,self.OnPaint)

    def OnPaint(self,event):
        dc = wx.PaintDC(self)
        dc.Clear()
        dc.DrawRectangle(20,20,50,50)

class OnPaintFrame(wx.Frame):

    def __init__(self,parent=None,title='OnDrawFrame'):
        wx.Frame.__init__(self,parent,-1,title)

        self.panel = OnPaintPanel(self)
        self.Bind(wx.EVT_CLOSE,self.OnClose)

    def OnClose(self,event):
        self.Destroy()

app = wx.App()
f = OnPaintFrame()
app.SetTopWindow(f)




-- 
Christopher Barker, Ph.D.
Oceanographer
                                     		
NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov




More information about the wxpython-users mailing list