As the error message says the GdkWindow
does not exist at that point, so you can't draw yet.
All the drawing should happen in the appropriate signal handler of the DrawingAreas
: In GTK 2 the signal is "expose-event"
and in the signal handler you should create the Cairo context and draw every time the handler is called. This answer has an example using a DrawingArea
subclass (which is a sensible idea)
Just a warning, in GTK3 this part is a bit different.