Skip to content

Gtk.ColorDialogButton

class — extends Widget, Accessible, Buildable, ConstraintTarget

Opens a color chooser dialog to select a color.

<picture> <source srcset="color-button-dark.png" media="(prefers-color-scheme: dark)"> <img alt="An example GtkColorDialogButton" src="color-button.png"> </picture>

It is suitable widget for selecting a color in a preference dialog.

CSS nodes

colorbutton
╰── button.color
    ╰── [content]

GtkColorDialogButton has a single CSS node with name colorbutton which contains a button node. To differentiate it from a plain GtkButton, it gets the .color style class.

Constructors

new

@classmethod
def new(cls, dialog: ColorDialog | None = ...) -> Widget

Creates a new GtkColorDialogButton with the given GtkColorDialog.

You can pass NULL to this function and set a GtkColorDialog later. The button will be insensitive until that happens.

Parameters:

  • dialog — the GtkColorDialog to use

Methods

get_dialog

def get_dialog(self) -> ColorDialog | None

Returns the GtkColorDialog of self.

get_rgba

def get_rgba(self) -> Gdk.RGBA

Returns the color of the button.

This function is what should be used to obtain the color that was chosen by the user. To get informed about changes, listen to "notify::rgba".

set_dialog

def set_dialog(self, dialog: ColorDialog) -> None

Sets a GtkColorDialog object to use for creating the color chooser dialog that is presented when the user clicks the button.

Parameters:

  • dialog — the new GtkColorDialog

set_rgba

def set_rgba(self, color: Gdk.RGBA) -> None

Sets the color of the button.

Parameters:

  • color — the new color

Properties

dialog

dialog: ColorDialog  # read/write

The GtkColorDialog that contains parameters for the color chooser dialog.

rgba

rgba: Gdk.RGBA  # read/write

The selected color.

This property can be set to give the button its initial color, and it will be updated to reflect the users choice in the color chooser dialog.

Listen to notify::rgba to get informed about changes to the buttons color.

Signals

activate

def on_activate(self) -> None: ...

Emitted when the color dialog button is activated.

The ::activate signal on GtkColorDialogButton is an action signal and emitting it causes the button to pop up its dialog.