Skip to content

Gtk.Frame

class — extends Widget, Accessible, Buildable, ConstraintTarget

Surrounds its child with a decorative frame and an optional label.

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

If present, the label is drawn inside the top edge of the frame. The horizontal position of the label can be controlled with Frame.set_label_align.

GtkFrame clips its child. You can use this to add rounded corners to widgets, but be aware that it also cuts off shadows.

GtkFrame as GtkBuildable

An example of a UI definition fragment with GtkFrame:

<object class="GtkFrame">
  <property name="label-widget">
    <object class="GtkLabel" id="frame_label"/>
  </property>
  <property name="child">
    <object class="GtkEntry" id="frame_content"/>
  </property>
</object>

CSS nodes

frame
├── <label widget>
╰── <child>

GtkFrame has a main CSS node with name “frame”, which is used to draw the visible border. You can set the appearance of the border using CSS properties like “border-style” on this node.

Accessibility

GtkFrame uses the AccessibleRole.group role.

Constructors

new

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

Creates a new GtkFrame, with optional label label.

If label is None, the label is omitted.

Parameters:

  • label — the text to use as the label of the frame

Methods

get_child

def get_child(self) -> Widget | None

Gets the child widget of frame.

get_label

def get_label(self) -> str | None

Returns the frame labels text.

If the frame's label widget is not a GtkLabel, None is returned.

get_label_align

def get_label_align(self) -> float

Retrieves the X alignment of the frame’s label.

get_label_widget

def get_label_widget(self) -> Widget | None

Retrieves the label widget for the frame.

set_child

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

Sets the child widget of frame.

Parameters:

  • child — the child widget

set_label

def set_label(self, label: str | None = ...) -> None

Creates a new GtkLabel with the label and sets it as the frame's label widget.

Parameters:

  • label — the text to use as the label of the frame

set_label_align

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

Sets the X alignment of the frame widget’s label.

The default value for a newly created frame is 0.0.

Parameters:

  • xalign — The position of the label along the top edge of the widget. A value of 0.0 represents left alignment; 1.0 represents right alignment.

set_label_widget

def set_label_widget(self, label_widget: Widget | None = ...) -> None

Sets the label widget for the frame.

This is the widget that will appear embedded in the top edge of the frame as a title.

Parameters:

  • label_widget — the new label widget

Virtual methods

do_compute_child_allocation

def do_compute_child_allocation(self, allocation: Allocation) -> None

Properties

child

child: Widget  # read/write

The child widget.

label

label: str  # read/write

Text of the frame's label.

label_widget

label_widget: Widget  # read/write

Widget to display in place of the usual frame label.

label_xalign

label_xalign: float  # read/write

The horizontal alignment of the label.