|
|
The DrawingArea widget offers a blank canvas covering a gtk.gdk.Window on which objects such as line, rectangle, arc, etc. can be drawn.
PyGTK uses Cairo library for such drawing processes. Cairo is a popular 2D vector graphics library. It is written in C., though, it has bindings in most Languages such as C++, Java, Python, PHP etc. Cairo library can be used to draw on normal output devices in numerous operating systems. It can also be used to create PDF, SVG and post-script files.
In order to do alter drawing operations, we must make the device on text of the target output object. In this case, meanwhile the drawing is appearing on gtk.DrawingArea widget, the device context of gdk.Window limited inside it is obtained. This class has a cairo-create() method which returns the device context.
The DrawingArea widget can be connected to the callbacks based on the following signals emitted by it −
Realize |
To take any necessary actions when the widget is instantiated on a particular display. |
configure_event |
To take any necessary actions when the widget changes size. |
expose_event |
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). |
The Mouse and Keyboard events can also be used to appeal callbacks by add_events() method of the gtk.Widget class.
Of specific attention is the expose-event signal which is produced when the DrawingArea canvas first comes up. The dissimilar approaches for drawing 2D objects that are defined in the Cairo library are called from this callback linked to the expose-event signal. These methods draw consistent objects on the Cairo device context.
The resulting are the obtainable drawing methods −
The resulting script draws different shapes and test using Cairo methods.
The above script will generate the resulting output –
|
|
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.