ColorButton

A ColorButton is used to select colour and transparency via a dialog which appears when the user clicks the button. It is commonly used in applications where space is limited.

Constructor

The ColorButton can be constructed using the following:

colorbutton = Gtk.ColorButton()

Methods

The title of the dialog which appears when clicking on the ColorButton can be set with:

colorbutton.set_title(title)

Examples

Below is an example of a ColorButton:

#!/usr/bin/env python3

from gi.repository import Gtk

class ColorButton(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.set_title('ColorButton')
        self.set_default_size(200, -1)
        self.connect('destroy', Gtk.main_quit)

        colorbutton = Gtk.ColorButton()
        colorbutton.connect('color-set', self.on_color_set)
        self.add(colorbutton)

    def on_color_set(self, colorbutton):
        color = colorbutton.get_rgba()

        red = (color.red * 255)
        green = (color.green * 255)
        blue = (color.blue * 255)

        print('Hex: #%02x%02x%02x' % (red, green, blue))

window = ColorButton()
window.show_all()

Gtk.main()

Download: ColorButton