PyGTK - Color Selection Dialog


Advertisements

This is a preconfigured Dialog in PyGTK API which lets the user to select and apply color. It internally embeds a gtk.ColorSelection widget.

The gtk.ColorScelection widget presents a colow wheel, and entry boxes for color parameters such as HSV and RGB. New color can be selected by manipulating color wheel or entering color parameters. Its get_current_color is useful for further processing.

Following is the prototype of the constructor of the gtk.ColorSelectionDialog class −

dlg = gtk.ColorSelectionDialog(title)

The current selected color is obtained from the colorsel attribute. The selected color is applied to a widget using modify_fg() or modify_bg() methods.

When the ColorDialog menu button is activated, the following callback function is executed −

def on_color(self, widget):
   dlg = gtk.ColorSelectionDialog("Select color")
   col = dlg.run()
   sel = dlg.colorsel.get_current_color()
   self.text.modify_fg(gtk.STATE_NORMAL, sel)

The chosen color is applied to the text in a label widget on the window −

Select Color

The following is the output −

Color Dialog Boxes
Advertisements