Avatar#

class Avatar(**properties: Any)#

Superclasses: Widget, InitiallyUnowned, Object

Implemented Interfaces: Accessible, Buildable, ConstraintTarget

A widget displaying an image, with a generated fallback.

https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1-latest/avatar.png

AdwAvatar is a widget that shows a round avatar.

AdwAvatar generates an avatar with the initials of the text on top of a colored background.

The color is picked based on the hash of the text.

If show_initials is set to FALSE, icon_name or avatar-default-symbolic is shown instead of the initials.

Use custom_image to set a custom image.

CSS nodes#

AdwAvatar has a single CSS node with name avatar.

Constructors#

class Avatar
classmethod new(size: int, text: str | None, show_initials: bool) Widget#

Creates a new AdwAvatar.

Parameters:
  • size – The size of the avatar

  • text – the text used to get the initials and color

  • show_initials – whether to use initials instead of an icon as fallback

Methods#

class Avatar
draw_to_texture(scale_factor: int) Texture#

Renders self into a Texture at scale_factor.

This can be used to export the fallback avatar.

Parameters:

scale_factor – The scale factor

get_custom_image() Paintable | None#

Gets the custom image paintable.

get_icon_name() str | None#

Gets the name of an icon to use as a fallback.

get_show_initials() bool#

Gets whether initials are used instead of an icon on the fallback avatar.

get_size() int#

Gets the size of the avatar.

get_text() str | None#

Gets the text used to generate the fallback initials and color.

set_custom_image(custom_image: Paintable | None = None) None#

Sets the custom image paintable.

Custom image is displayed instead of initials or icon.

Parameters:

custom_image – a custom image

set_icon_name(icon_name: str | None = None) None#

Sets the name of an icon to use as a fallback.

If no name is set, avatar-default-symbolic will be used.

Parameters:

icon_name – the icon name

set_show_initials(show_initials: bool) None#

Sets whether to use initials instead of an icon on the fallback avatar.

See icon_name for how to change the fallback icon.

Parameters:

show_initials – whether to use initials instead of an icon as fallback

set_size(size: int) None#

Sets the size of the avatar.

Parameters:

size – The size of the avatar

set_text(text: str | None = None) None#

Sets the text used to generate the fallback initials and color.

It’s only used to generate the color if show_initials is FALSE.

Parameters:

text – the text used to get the initials and color

Properties#

class Avatar
props.custom_image: Paintable#

The type of the None singleton.

props.icon_name: str#

The type of the None singleton.

props.show_initials: bool#

The type of the None singleton.

props.size: int#

The type of the None singleton.

props.text: str#

The type of the None singleton.