Skip to content

Gtk.AspectFrame

class — extends Widget, Accessible, Buildable, ConstraintTarget

Preserves the aspect ratio of its child.

The frame can respect the aspect ratio of the child widget, or use its own aspect ratio.

CSS nodes

GtkAspectFrame uses a CSS node with name aspectframe.

Accessibility

Until GTK 4.10, GtkAspectFrame used the AccessibleRole.group role.

Starting from GTK 4.12, GtkAspectFrame uses the AccessibleRole.generic role.

Constructors

new

@classmethod
def new(cls, xalign: float, yalign: float, ratio: float, obey_child: bool) -> Widget

Create a new GtkAspectFrame.

Parameters:

  • xalign — Horizontal alignment of the child within the parent. Ranges from 0.0 (left aligned) to 1.0 (right aligned)
  • yalign — Vertical alignment of the child within the parent. Ranges from 0.0 (top aligned) to 1.0 (bottom aligned)
  • ratio — The desired aspect ratio.
  • obey_child — If True, ratio is ignored, and the aspect ratio is taken from the requistion of the child.

Methods

get_child

def get_child(self) -> Widget | None

Gets the child widget of self.

get_obey_child

def get_obey_child(self) -> bool

Returns whether the child's size request should override the set aspect ratio of the GtkAspectFrame.

get_ratio

def get_ratio(self) -> float

Returns the desired aspect ratio of the child.

get_xalign

def get_xalign(self) -> float

Returns the horizontal alignment of the child within the allocation of the GtkAspectFrame.

get_yalign

def get_yalign(self) -> float

Returns the vertical alignment of the child within the allocation of the GtkAspectFrame.

set_child

def set_child(self, child: Widget | None = ...) -> None

Sets the child widget of self.

Parameters:

  • child — the child widget

set_obey_child

def set_obey_child(self, obey_child: bool) -> None

Sets whether the aspect ratio of the child's size request should override the set aspect ratio of the GtkAspectFrame.

Parameters:

  • obey_child — If True, ratio is ignored, and the aspect ratio is taken from the requisition of the child.

set_ratio

def set_ratio(self, ratio: float) -> None

Sets the desired aspect ratio of the child.

Parameters:

  • ratio — aspect ratio of the child

set_xalign

def set_xalign(self, xalign: float) -> None

Sets the horizontal alignment of the child within the allocation of the GtkAspectFrame.

Parameters:

  • xalign — horizontal alignment, from 0.0 (left aligned) to 1.0 (right aligned)

set_yalign

def set_yalign(self, yalign: float) -> None

Sets the vertical alignment of the child within the allocation of the GtkAspectFrame.

Parameters:

  • yalign — horizontal alignment, from 0.0 (top aligned) to 1.0 (bottom aligned)

Properties

child

child: Widget  # read/write

The child widget.

obey_child

obey_child: bool  # read/write

Whether the GtkAspectFrame should use the aspect ratio of its child.

ratio

ratio: float  # read/write

The aspect ratio to be used by the GtkAspectFrame.

This property is only used if AspectFrame.obey-child is set to False.

xalign

xalign: float  # read/write

The horizontal alignment of the child.

yalign

yalign: float  # read/write

The vertical alignment of the child.