I'd like to draw inside my Gtk.DrawingArea objects. I have to connect the drawing function to the "draw" event, not to the "expose-event", because i'm working with gtk3.
But this doesn't work.
Here is my code:
def draw(widget, context, args=()):
context.set_source_rgb(0.9, 0, 0.1) #rosso
context.rectangle(0, 0, widget.get_allocated_width(), widget.get_allocated_height())
context.fill()
builder = Gtk.Builder()
builder.add_from_file('menuitem.glade')
builder.get_object('drawingarea1').connect("draw", draw)
builder.get_object('drawingarea1').show()
builder.get_object('window1').show() #there are many drawing areas inside a window (they are inside a grid)
Gtk.main()
Adding DrawingAreas to a Grid is a bit problematic if hexpand and vexpand are not set. Additionally adding width_request and height_request is needed (or some other layout organization which forces the DrawingArea to have a size), otherwise the initial window size will be tiny or not visible. The following shows your code working with a Grid and two DrawingAreas: