After a couple days of trying to get this work, looking at the samples and demos included with wxPython, I think I'm ready to admit that I need some help.
I'm simply trying to make a silly program in wxPython as an introduction to using the system. I have learned that if I wish to draw abitrary things inside of a Window object, I have to use a DC. Specifically, a ClientDC (Or a PaintDC if I'm handling an EVT_PAINT event, which I'm not at the moment.).
I can't quite seem to get a ClientDC to actually draw anything. My script runs just fine, but only returns an empty window. In frustration, I have turned to simply creating a Frame and using a ClientDC to fill it with red, to similar effect.
What I've basically done is create a class which inherits from wx.Frame, and, in its __init__ function, I have defined a ClientDC and told it to fill the frame with red. Afterwards I simply create a PySimpleApp, instantiate an instance of the class, Show the Frame, and enter the MainLoop. My code looks like this.
import wx
class CCFrame(wx.Frame):
def __init__(self, parent, id=-1):
wx.Frame.__init__(self, parent, id=-1)
dc = wx.ClientDC(self)
dc.FloodFill(0,0,(255,0,0))
def main():
CCApp = wx.PySimpleApp()
MainFrame = CCFrame(None)
MainFrame.Show(True)
CCApp.MainLoop()
main()
I'm running this on an Intel Mac (MacOS X 10.4.9), with Python 2.4, and wxPython 2.8.4.0.
I just get a blank window. I'm going for a window filled with red. What's going wrong here? I've also tried experimenting with moving the DC usage out into the main loop before the MainLoop is entered (dc = wx.ClientDC(MainFrame), etc). Still doesn't work.
Is there something obvious I'm missing? What do I need to do to get the DC to actually draw something?
Am I doing something altogether wrong? is there a better/easier way to accomplish drawing an image in a window than using DCs?