how to draw in a window, device context
7stud
bbxx789_05ss at yahoo.com
Mon Jun 4 12:46:48 PDT 2007
Chris Mellon <arkanes <at> gmail.com> writes:
> This "works" as far as it goes, but since you're drawing in the
> __init__ it gets erased when the window is actually show and
> repainted. You need to do your drawing in an EVT_PAINT handler
> instead. There's a chapter in wxPIA about this. I believe it's called
> "Implementing Custom Controls", but I don't have my copy handy so I
> can't check this.
>
Thanks for the explanation. The cobwebs are clearing a bit from the
memories of some C++ GUI programming I once did. Now I seem to
recall that a window is painted when:
1) it's initially displayed
2) it's covered up and then uncovered.
And in order to draw in a window, you have to intercept a paint
message that is issued in response to those events, and then draw
your window the way you want it.
Unfortunately, "wxPython in Action" fails to mention the fact that
you need to listen for wx.EVT_PAINT and then draw the
window inside the event handler. There is no mention of that fact in
section 6.1 "Drawing to the Screen" nor in section 12.2.2 "How do
I draw to a device context?", and the examples are so long and
convoluted, it's not possible fora beginner to discern that requirement
from the examples.
More information about the wxpython-users
mailing list