Helder Oliveira wrote:
hello guys i am trying to draw using the pycrust and i am doing like this:
>>> import wx
>>> app = wx.PySimpleApp()
>>> frame = wx.Frame(None,-1,"Trying to draw")
>>> panel = wx.Panel(frame,-1)
>>> panel.SetBackgroundColour("WHITE")
True
>>> dc = wx.PaintDC(panel)
wx.PaneDC can only be used in EVT_PAINT handlers. To draw outside of a paint handler you should use wx.ClientDC.
>>> dc.Clear()
>>> dc.SetPen(wx.Pen("RED",3))
>>> dc.DrawLine(10,10,50,50)
>>> panel.Show()
False
>>> frame.Show()
However even if you did use a wx.ClientDC in this case it still would not show. When you draw to a DC it is not automatically retained and refreshed when the window is shown or uncovered. So since your line was drawn before the frame was shown it will be lost, because when it is shown there will be a paint event, and the default one will just clear the panel to its background colour.
In other words, the following in PyCrust will work, but as soon as you cover and expose the window the line will be lost:
>>> import wx
>>> frame = wx.Frame(None,-1,"Trying to draw")
>>> panel = wx.Panel(frame,-1)
>>> panel.SetBackgroundColour("WHITE")
True
>>> frame.Show()
True
>>> dc = wx.ClientDC(panel)
>>> dc.SetPen(wx.Pen("RED", 3))
>>> dc.DrawLine(10,10, 50,50)
>>>
To make the drawing survive across window refreshes you can just move your code to a paint event handler. Continuing the prior PyCrust session:
>>> def OnPaint(evt):
... dc = wx.PaintDC(panel)
... dc.SetPen(wx.Pen("RED", 3))
... dc.DrawLine(10,10, 50,50)
...
···
panel.Bind(wx.EVT_PAINT, OnPaint)
>>> panel.Refresh()
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!