Skip to content

Gtk.ScaleButton

class — extends Widget, Accessible, AccessibleRange, Buildable, ConstraintTarget, Orientable

Provides a button which pops up a scale widget.

This kind of widget is commonly used for volume controls in multimedia applications, and GTK provides a VolumeButton subclass that is tailored for this use case.

Shortcuts and Gestures

The following signals have default keybindings:

CSS nodes

scalebutton.scale
╰── button.toggle
    ╰── <icon>

GtkScaleButton has a single CSS node with name scalebutton and .scale style class, and contains a button node with a .toggle style class.

Constructors

new

@classmethod
def new(cls, min: float, max: float, step: float, icons: list[str] | None = ...) -> Widget

Creates a GtkScaleButton.

The new scale button has a range between min and max, with a stepping of step.

Parameters:

  • min — the minimum value of the scale (usually 0)
  • max — the maximum value of the scale (usually 100)
  • step — the stepping of value when a scroll-wheel event, or up/down arrow event occurs (usually 2)
  • icons — a None-terminated array of icon names, or None if you want to set the list later with ScaleButton.set_icons

Methods

get_active

def get_active(self) -> bool

Queries a GtkScaleButton and returns its current state.

Returns True if the scale button is pressed in and False if it is raised.

get_adjustment

def get_adjustment(self) -> Adjustment

Gets the GtkAdjustment associated with the GtkScaleButton’s scale.

See Range.get_adjustment for details.

get_has_frame

def get_has_frame(self) -> bool

Returns whether the button has a frame.

get_minus_button

def get_minus_button(self) -> Button

Retrieves the minus button of the GtkScaleButton.

get_plus_button

def get_plus_button(self) -> Button

Retrieves the plus button of the GtkScaleButton.

get_popup

def get_popup(self) -> Widget

Retrieves the popup of the GtkScaleButton.

get_value

def get_value(self) -> float

Gets the current value of the scale button.

set_adjustment

def set_adjustment(self, adjustment: Adjustment) -> None

Sets the GtkAdjustment to be used as a model for the GtkScaleButton’s scale.

See Range.set_adjustment for details.

Parameters:

  • adjustment — a GtkAdjustment

set_has_frame

def set_has_frame(self, has_frame: bool) -> None

Sets the style of the button.

Parameters:

  • has_frame — whether the button should have a visible frame

set_icons

def set_icons(self, icons: list[str]) -> None

Sets the icons to be used by the scale button.

Parameters:

  • icons — a None-terminated array of icon names

set_value

def set_value(self, value: float) -> None

Sets the current value of the scale.

If the value is outside the minimum or maximum range values, it will be clamped to fit inside them.

The scale button emits the ScaleButton.value-changed signal if the value changes.

Parameters:

  • value — new value of the scale button

Virtual methods

do_value_changed

def do_value_changed(self, value: float) -> None

Properties

active

active: bool  # read-only

If the scale button should be pressed in.

adjustment

adjustment: Adjustment  # read/write

The GtkAdjustment that is used as the model.

has_frame

has_frame: bool  # read/write

If the scale button has a frame.

icons

icons: list[str]  # read/write

The names of the icons to be used by the scale button.

The first item in the array will be used in the button when the current value is the lowest value, the second item for the highest value. All the subsequent icons will be used for all the other values, spread evenly over the range of values.

If there's only one icon name in the icons array, it will be used for all the values. If only two icon names are in the icons array, the first one will be used for the bottom 50% of the scale, and the second one for the top 50%.

It is recommended to use at least 3 icons so that the GtkScaleButton reflects the current value of the scale better for the users.

value

value: float  # read/write

The value of the scale.

Signals

popdown

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

Emitted to dismiss the popup.

This is a keybinding signal.

The default binding for this signal is <kbd>Escape</kbd>.

popup

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

Emitted to popup the scale widget.

This is a keybinding signal.

The default bindings for this signal are <kbd>Space</kbd>, <kbd>Enter</kbd> and <kbd>Return</kbd>.

value-changed

def on_value_changed(self, value: float) -> None: ...

Emitted when the value field has changed.