Gtk.Picture¶
- Subclasses:
None
Methods¶
- Inherited:
Gtk.Widget (183), GObject.Object (37), Gtk.Accessible (17), Gtk.Buildable (1)
- Structs:
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Gtk.Widget (25), GObject.Object (7), Gtk.Accessible (6), Gtk.Buildable (9)
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
|---|---|---|---|
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
d/r/w/en |
|
||
r/w/en |
Signals¶
- Inherited:
Fields¶
- Inherited:
Class Details¶
- class Gtk.Picture(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
Displays a
GdkPaintable.picture> <source srcset=”picture-dark.png” media=”(prefers-color-scheme: dark)”> <img alt=”An example
Gtk.Picture" src=”picture.png”> </picture>Many convenience functions are provided to make pictures simple to use. For example, if you want to load an image from a file, and then display it, there’s a convenience function to do this:
``c GtkWidget *widget = gtk_picture_new_for_filename (“myfile.png”); ``
If the file isn’t loaded successfully, the picture will contain a “broken image” icon similar to that used in many web browsers. If you want to handle errors in loading the file yourself, for example by displaying an error message, then load the image with [ctor`Gdk`.Texture.new_from_file], then create the
GtkPicturewith [ctor`Gtk`.Picture.new_for_paintable].Sometimes an application will want to avoid depending on external data files, such as image files. See the documentation of
GResourcefor details. In this case, [ctor`Gtk`.Picture.new_for_resource] and [method`Gtk`.Picture.set_resource] should be used.GtkPicturedisplays an image at its natural size. See [class`Gtk`.Image] if you want to display a fixed-size image, such as an icon.- Sizing the paintable
You can influence how the paintable is displayed inside the
GtkPictureby changing [property`Gtk`.Picture:content-fit]. See [enum`Gtk`.ContentFit] for details. [property`Gtk`.Picture:can-shrink] can be unset to make sure that paintables are never made smaller than their ideal size - but be careful if you do not know the size of the paintable in use (like when displaying user-loaded images). This can easily cause the picture to grow larger than the screen. And [property`Gtk`.Widget:halign] and [property`Gtk`.Widget:valign] can be used to make sure the paintable doesn’t fill all available space but is instead displayed at its original size.- CSS nodes
GtkPicturehas a single CSS node with the namepicture.- Accessibility
GtkPictureuses the [enum`Gtk`.AccessibleRole.img] role.- classmethod new()[source]¶
- Returns:
a newly created
GtkPicturewidget.- Return type:
Creates a new empty
GtkPicturewidget.
- classmethod new_for_file(file)[source]¶
- Parameters:
- Returns:
a new
GtkPicture- Return type:
Creates a new
GtkPicturedisplaying the given file.If the file isn’t found or can’t be loaded, the resulting
GtkPictureis empty.If you need to detect failures to load the file, use [ctor`Gdk`.Texture.new_from_file] to load the file yourself, then create the
GtkPicturefrom the texture.
- classmethod new_for_filename(filename)[source]¶
- Parameters:
- Returns:
a new
GtkPicture- Return type:
Creates a new
GtkPicturedisplaying the file filename.This is a utility function that calls [ctor`Gtk`.Picture.new_for_file]. See that function for details.
- classmethod new_for_paintable(paintable)[source]¶
- Parameters:
paintable (
Gdk.PaintableorNone) – aGdkPaintable- Returns:
a new
GtkPicture- Return type:
Creates a new
GtkPicturedisplaying paintable.The
GtkPicturewill track changes to the paintable and update its size and contents in response to it.
- classmethod new_for_pixbuf(pixbuf)[source]¶
- Parameters:
pixbuf (
GdkPixbuf.PixbuforNone) – aGdkPixbuf- Returns:
a new
GtkPicture- Return type:
Creates a new
GtkPicturedisplaying pixbuf.This is a utility function that calls [ctor`Gtk`.Picture.new_for_paintable], See that function for details.
The pixbuf must not be modified after passing it to this function.
Deprecated since version 4.12: Use [ctor`Gtk`.Picture.new_for_paintable] and [ctor`Gdk`.Texture.new_for_pixbuf] instead
- classmethod new_for_resource(resource_path)[source]¶
- Parameters:
- Returns:
a new
GtkPicture- Return type:
Creates a new
GtkPicturedisplaying the resource at resource_path.This is a utility function that calls [ctor`Gtk`.Picture.new_for_file]. See that function for details.
- get_alternative_text()[source]¶
-
Gets the alternative textual description of the picture.
The returned string will be
Noneif the picture cannot be described textually.
- get_content_fit()[source]¶
- Returns:
the content fit mode
- Return type:
Returns the fit mode for the content of the
GtkPicture.See [enum`Gtk`.ContentFit] for details.
New in version 4.8.
- get_file()[source]¶
-
Gets the
GFilecurrently displayed if self is displaying a file.If self is not displaying a file, for example when [method`Gtk`.Picture.set_paintable] was used, then
Noneis returned.
- get_keep_aspect_ratio()[source]¶
-
Returns whether the
GtkPicturepreserves its contents aspect ratio.Deprecated since version 4.8: Use [method`Gtk`.Picture.get_content_fit] instead. This will now return
FALSEonly if [property`Gtk`.Picture:content-fit] isGTK_CONTENT_FIT_FILL. ReturnsTRUEotherwise.
- get_paintable()[source]¶
- Returns:
the displayed paintable
- Return type:
Gets the
GdkPaintablebeing displayed by theGtkPicture.
- set_alternative_text(alternative_text)[source]¶
-
Sets an alternative textual description for the picture contents.
It is equivalent to the “alt” attribute for images on websites.
This text will be made available to accessibility tools.
If the picture cannot be described textually, set this property to
None.
- set_can_shrink(can_shrink)[source]¶
- Parameters:
can_shrink (
bool) – if self can be made smaller than its contents
If set to
True, the self can be made smaller than its contents.The contents will then be scaled down when rendering.
If you want to still force a minimum size manually, consider using [method`Gtk`.Widget.set_size_request].
Also of note is that a similar function for growing does not exist because the grow behavior can be controlled via [method`Gtk`.Widget.set_halign] and [method`Gtk`.Widget.set_valign].
- set_content_fit(content_fit)[source]¶
- Parameters:
content_fit (
Gtk.ContentFit) – the content fit mode
Sets how the content should be resized to fit the
GtkPicture.See [enum`Gtk`.ContentFit] for details.
New in version 4.8.
- set_file(file)[source]¶
-
Makes self load and display file.
See [ctor`Gtk`.Picture.new_for_file] for details.
- set_filename(filename)[source]¶
-
Makes self load and display the given filename.
This is a utility function that calls [method`Gtk`.Picture.set_file].
- set_keep_aspect_ratio(keep_aspect_ratio)[source]¶
- Parameters:
keep_aspect_ratio (
bool) – whether to keep aspect ratio
If set to
True, the self will render its contents according to their aspect ratio.That means that empty space may show up at the top/bottom or left/right of self.
If set to
Falseor if the contents provide no aspect ratio, the contents will be stretched over the picture’s whole area.Deprecated since version 4.8: Use [method`Gtk`.Picture.set_content_fit] instead. If still used, this method will always set the [property`Gtk`.Picture:content-fit] property to
GTK_CONTENT_FIT_CONTAINif keep_aspect_ratio is true, otherwise it will set it toGTK_CONTENT_FIT_FILL.
- set_paintable(paintable)[source]¶
- Parameters:
paintable (
Gdk.PaintableorNone) – aGdkPaintable
Makes self display the given paintable.
If paintable is
None, nothing will be displayed.See [ctor`Gtk`.Picture.new_for_paintable] for details.
- set_pixbuf(pixbuf)[source]¶
- Parameters:
pixbuf (
GdkPixbuf.PixbuforNone) – aGdkPixbuf
Sets a
GtkPictureto show aGdkPixbuf.See [ctor`Gtk`.Picture.new_for_pixbuf] for details.
This is a utility function that calls [method`Gtk`.Picture.set_paintable].
Deprecated since version 4.12: Use [method`Gtk`.Picture.set_paintable] instead
Property Details¶
- Gtk.Picture.props.alternative_text¶
- Name:
alternative-text- Type:
- Default Value:
- Flags:
The alternative textual description for the picture.
- Gtk.Picture.props.can_shrink¶
- Name:
can-shrink- Type:
- Default Value:
- Flags:
If the
GtkPicturecan be made smaller than the natural size of its contents.
- Gtk.Picture.props.content_fit¶
- Name:
content-fit- Type:
- Default Value:
- Flags:
How the content should be resized to fit inside the
GtkPicture.New in version 4.8.
- Gtk.Picture.props.file¶
- Name:
file- Type:
- Default Value:
- Flags:
The
GFilethat is displayed orNoneif none.
- Gtk.Picture.props.keep_aspect_ratio¶
- Name:
keep-aspect-ratio- Type:
- Default Value:
- Flags:
Whether the
Gtk.Picturewill render its contents trying to preserve the aspect ratio.Deprecated since version 4.8: Use [property`Gtk`.Picture:content-fit] instead.
- Gtk.Picture.props.paintable¶
- Name:
paintable- Type:
- Default Value:
- Flags:
The
GdkPaintableto be displayed by thisGtkPicture.