ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> wxPython-users
wxPython-users
Re: [wxPython-users] Basics of drawing on a wx.Panel
by Robin Dunn other posts by this author
Dec 12 2004 8:33AM messages near this date
[wxPython-users] Basics of drawing on a wx.Panel | Re: [wxPython-users] Basics of drawing on a wx.Panel
pit.grinja@[...].de wrote:
>  Hello,
>  I have recently started to explore the wxPython opportunities to generate
>  small graphics. As a very first example, I wrote the following:
>  import wx
>  #____________________________
>  
>  class MainWindow(wx.Frame):
>      def __init__(self,parent,id,title):
>          wx.Frame.__init__(self,parent,-1, title,
>  style=wx.DEFAULT_FRAME_STYLE)
>          self.panel = wx.Panel(self,-1)
>          self.sizer = wx.BoxSizer(wx.HORIZONTAL)
>          self.sizer.Add(self.panel,1,wx.ALL)
>          self.SetSize(wx.Size(400,400))
>          self.SetSizer(self.sizer)
>          self.SetAutoLayout(True)
>          self.sizer.Fit(self)
>          dc = wx.ClientDC(self.panel)
>          dc.BeginDrawing()
>          dc.SetPen(wx.Pen(wx.RED,20))
>          dc.DrawLine(5,200,50,300)
>          dc.EndDrawing()
>          self.Refresh()
>  
>  
>  app = wx.PySimpleApp()
>  frame = MainWindow(None, -1, "Draw Demo")
>  frame.Show(True)
>  app.MainLoop()
>  
>  But I cannot see the expected line. What have I missed?

When you draw on a window it is not persistent.  You have to catch the 
EVT_PAINT event and  redraw at least the portions of the window that the 
OS tells you needs refreshing (or just do the whole thing.)  In your 
example you are drawing to a window that has not been shown yet so none 
of your drawing will be seen, and then when it is shown the system is 
sending a EVT_PAINT and since you are not catching it the window will 
just be cleared using the backgroudn colour. Look at the ScrolledWindow 
sample in the demo, it is an example of painting custom things on a window.

-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!


---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@[...].org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
Thread:

Robin Dunn
Vladimir Ignatov

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved