Skip to content

Gtk.ColorButton

class — extends Widget, Accessible, Buildable, ColorChooser, ConstraintTarget

:::warning Deprecated since 4.10 This API is deprecated. :::

The GtkColorButton allows to open a color chooser dialog to change the color.

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

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

CSS nodes

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

GtkColorButton 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) -> Widget

:::warning Deprecated since 4.10 This API is deprecated. :::

Creates a new color button.

This returns a widget in the form of a small button containing a swatch representing the current selected color. When the button is clicked, a color chooser dialog will open, allowing the user to select a color. The swatch will be updated to reflect the new color when the user finishes.

new_with_rgba

@classmethod
def new_with_rgba(cls, rgba: Gdk.RGBA) -> Widget

Creates a new color button showing the given color.

Parameters:

  • rgba — A GdkRGBA to set the current color with

Methods

get_modal

def get_modal(self) -> bool

:::warning Deprecated since 4.10 This API is deprecated. :::

Gets whether the dialog is modal.

get_title

def get_title(self) -> str

:::warning Deprecated since 4.10 This API is deprecated. :::

Gets the title of the color chooser dialog.

set_modal

def set_modal(self, modal: bool) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Sets whether the dialog should be modal.

Parameters:

  • modalTrue to make the dialog modal

set_title

def set_title(self, title: str) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Sets the title for the color chooser dialog.

Parameters:

  • title — String containing new window title

Properties

modal

modal: bool  # read/write

Whether the color chooser dialog should be modal.

show_editor

show_editor: bool  # read/write

Whether the color chooser should open in editor mode.

This property should be used in cases where the palette in the editor would be redundant, such as when the color button is already part of a palette.

title

title: str  # read/write

The title of the color chooser dialog

Signals

activate

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

Emitted to when the color button is activated.

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

color-set

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

Emitted when the user selects a color.

When handling this signal, use ColorChooser.get_rgba to find out which color was just selected.

Note that this signal is only emitted when the user changes the color. If you need to react to programmatic color changes as well, use the notify::rgba signal.