gtk.DrawingArea — a widget for custom user interface elements.


class gtk.DrawingArea(gtk.Widget):


+-- gobject.GObject
  +-- gtk.Object
    +-- gtk.Widget
      +-- gtk.DrawingArea

Implemented Interfaces

gtk.DrawingArea implements gtk.Buildable

gtk.DrawingArea Properties

gtk.Object Properties

gtk.Widget Properties

gtk.DrawingArea Style Properties

gtk.Widget Style Properties

gtk.DrawingArea Signal Prototypes

gobject.GObject Signal Prototypes

gtk.Object Signal Prototypes

gtk.Widget Signal Prototypes


The gtk.DrawingArea widget is used for creating custom user interface elements. It's essentially a blank widget containing a gtk.gdk.Window that you can draw on. The contained gtk.gdk.Window is accessed using the gtk.Widget "window" attribute as:

  gdkwindow = drawingarea.window

Since a gtk.gdk.Window is a subclass of gtk.gdk.Drawable, all of the gtk.gdk.Drawable methods are available for drawing on the gtk.DrawingArea's gdkwindow.

After creating a drawing area, the application may want to connect to:

  • Mouse and button press signals to respond to input from the user. Use the gtk.Widget.add_events() method to enable events you wish to receive. To receive keyboard events, you will need to set the gtk.CAN_FOCUS flag on the drawing area

  • The "realize" signal to take any necessary actions when the widget is instantiated on a particular display.

  • The "configure_event" signal to take any necessary actions when the widget changes size.

  • The "expose_event" signal to handle redrawing the contents of the widget when a drawing area first comes on screen, or when it's covered by another window and then uncovered (exposed). You can also force an expose event by adding to the "damage region" of the drawing area's window using the gtk.Widget.queue_draw_area() method.

See the Drawing Area chapter in the tutorial for more information on using a gtk.DrawingArea.

Sometimes a gtk.Image is a useful alternative to a drawing area. You can put a gtk.gdk.Pixmap in the gtk.Image and draw to the gtk.gdk.Pixmap, calling the gtk.Widget.queue_draw() method on the gtk.Image when you want to refresh to the screen.



Returns :

a new drawingarea widget

Creates a new gtk.DrawingArea widget.