About GNOME · Users · Developers · Bindings

Example Code

(in no particular order...)


A very contrived and pointless example that exercises some of the more useful features of Gtk2::SimpleList. In fact, this is just some stuff wrapped around the code from the synopsis.

This example produces nearly identical output and uses almost the same driver driver code as colorbutton-simple, but uses Glib::Object::Subclass to derive a "real" Gtk widget, e.g., a class that is registered with the GLib type system and could be used from C code as a native GtkWidget. The distinction is important, for example if you are running in a Perl interpreter embedded in a gui program which may need to use the widget you've created. In this trivial example the extra power of the Glib::Object subclassing may seem like overkill, but this is a nice and clean way to demonstrate how to create a new signal (color-changed) and override virtual methods (on_show gets called as part of the machinery behind $foo->show).

This is the scribble sample from the the Gtk+ source and tutorial, ported to gtk2-perl. This simple drawing application demonstrates creating a window and connecting signals, the basics of pointer and expose event handling, using drawing primitives, and using a backing pixmap.

Here's an example of the simple way to create your own widgets. If your object will be used only from Perl code, and you don't need fancy stuff like new signals or virtual overrides, then use can just use normal Perl OO techniques to create a new object that inherits an existing one. This code creates a button with a color patch inside, which pops up a color selection dialog when clicked. Compare this with colorbutton-full.


This is an example of how to create a custom widget, using the Glib::Object::Subclass module to derive a new type from the Gtk2::DrawingArea. It also demonstrates pointer and cursor handling, creating and emitting new signals, object properties, and even how to draw text and shapes directly onto a window.