Gtk.Image¶
Methods¶
| Inherited: | Gtk.Misc (4), Gtk.Widget (278), GObject.Object (37), Gtk.Buildable (10) | 
|---|---|
| Structs: | Gtk.WidgetClass (12), GObject.ObjectClass (5) | 
| class | new() | 
| class | new_from_animation(animation) | 
| class | new_from_file(filename) | 
| class | new_from_gicon(icon, size) | 
| class | new_from_icon_name(icon_name, size) | 
| class | new_from_icon_set(icon_set, size) | 
| class | new_from_pixbuf(pixbuf) | 
| class | new_from_resource(resource_path) | 
| class | new_from_stock(stock_id, size) | 
| class | new_from_surface(surface) | 
| clear() | |
| get_animation() | |
| get_gicon() | |
| get_icon_name() | |
| get_icon_set() | |
| get_pixbuf() | |
| get_pixel_size() | |
| get_stock() | |
| get_storage_type() | |
| set_from_animation(animation) | |
| set_from_file(filename) | |
| set_from_gicon(icon, size) | |
| set_from_icon_name(icon_name, size) | |
| set_from_icon_set(icon_set, size) | |
| set_from_pixbuf(pixbuf) | |
| set_from_resource(resource_path) | |
| set_from_stock(stock_id, size) | |
| set_from_surface(surface) | |
| set_pixel_size(pixel_size) | 
Virtual Methods¶
| Inherited: | Gtk.Widget (82), GObject.Object (7), Gtk.Buildable (10) | 
|---|
Properties¶
| Inherited: | Gtk.Misc (4), Gtk.Widget (39) | 
|---|
| Name | Type | Flags | Short Description | 
|---|---|---|---|
| file | str | r/w | Filename to load and display | 
| gicon | Gio.Icon | r/w | The Gio.Iconbeing displayed | 
| icon-name | str | r/w | The name of the icon from the icon theme | 
| icon-set | Gtk.IconSet | d/r/w | Icon set to display deprecated | 
| icon-size | int | r/w/en | Symbolic size to use for stock icon, icon set or named icon | 
| pixbuf | GdkPixbuf.Pixbuf | r/w | A GdkPixbuf.Pixbufto display | 
| pixbuf-animation | GdkPixbuf.PixbufAnimation | r/w | GdkPixbuf.PixbufAnimationto display | 
| pixel-size | int | r/w/en | Pixel size to use for named icon | 
| resource | str | r/w | The resource path being displayed | 
| stock | str | d/r/w | Stock ID for a stock image to display deprecated | 
| storage-type | Gtk.ImageType | r | The representation being used for image data | 
| surface | cairo.Surface | r/w | A cairo.Surfaceto display | 
| use-fallback | bool | r/w/en | Whether to use icon names fallback | 
Style Properties¶
| Inherited: | Gtk.Widget (17) | 
|---|
Signals¶
| Inherited: | Gtk.Widget (69), GObject.Object (1) | 
|---|
Class Details¶
- 
class Gtk.Image(**kwargs)¶
- Bases: - Gtk.Misc- Abstract: - No - Structure: - Gtk.ImageClass- The - Gtk.Imagewidget displays an image. Various kinds of object can be displayed as an image; most typically, you would load a- GdkPixbuf.Pixbuf(“pixel buffer”) from a file, and then display that. There’s a convenience function to do this,- Gtk.Image.new_from_file(), used as follows:- GtkWidget *image; image = gtk_image_new_from_file ("myfile.png"); - If the file isn’t loaded successfully, the image 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 - GdkPixbuf.Pixbuf.new_from_file(), then create the- Gtk.Imagewith- Gtk.Image.new_from_pixbuf().- The image file may contain an animation, if so the - Gtk.Imagewill display an animation (- GdkPixbuf.PixbufAnimation) instead of a static image.- Gtk.Imageis a subclass of- Gtk.Misc, which implies that you can align it (center, left, right) and add padding to it, using- Gtk.Miscmethods.- Gtk.Imageis a “no window” widget (has no- Gdk.Windowof its own), so by default does not receive events. If you want to receive events on the image, such as button clicks, place the image inside a- Gtk.EventBox, then connect to the event signals on the event box.- Handling button press events on a Gtk.Image.
 - static gboolean button_press_callback (GtkWidget *event_box, GdkEventButton *event, gpointer data) { g_print ("Event box clicked at coordinates %f,%f\n", event->x, event->y); // Returning TRUE means we handled the event, so the signal // emission should be stopped (don’t call any further callbacks // that may be connected). Return FALSE to continue invoking callbacks. return TRUE; } static GtkWidget* create_image (void) { GtkWidget *image; GtkWidget *event_box; image = gtk_image_new_from_file ("myfile.png"); event_box = gtk_event_box_new (); gtk_container_add (GTK_CONTAINER (event_box), image); g_signal_connect (G_OBJECT (event_box), "button_press_event", G_CALLBACK (button_press_callback), image); return image; } - When handling events on the event box, keep in mind that coordinates in the image may be different from event box coordinates due to the alignment and padding settings on the image (see - Gtk.Misc). The simplest way to solve this is to set the alignment to 0.0 (left/top), and set the padding to zero. Then the origin of the image will be the same as the origin of the event box.- Sometimes an application will want to avoid depending on external data files, such as image files. GTK+ comes with a program to avoid this, called “gdk-pixbuf-csource”. This library allows you to convert an image into a C variable declaration, which can then be loaded into a - GdkPixbuf.Pixbufusing- GdkPixbuf.Pixbuf.new_from_inline().- CSS nodes
 - Gtk.Imagehas a single CSS node with the name image. The style classes may appear on image CSS nodes: .icon-dropshadow, .lowres-icon.- 
classmethod new()[source]¶
- Returns: - a newly created - Gtk.Imagewidget.- Return type: - Gtk.Widget- Creates a new empty - Gtk.Imagewidget.
 - 
classmethod new_from_animation(animation)[source]¶
- Parameters: - animation ( - GdkPixbuf.PixbufAnimation) – an animation- Returns: - a new - Gtk.Imagewidget- Return type: - Gtk.Widget- Creates a - Gtk.Imagedisplaying the given animation. The- Gtk.Imagedoes not assume a reference to the animation; you still need to unref it if you own references.- Gtk.Imagewill add its own reference rather than adopting yours.- Note that the animation frames are shown using a timeout with - GLib.PRIORITY_DEFAULT. When using animations to indicate busyness, keep in mind that the animation will only be shown if the main loop is not busy with something that has a higher priority.
 - 
classmethod new_from_file(filename)[source]¶
- Parameters: - filename ( - str) – a filename- Returns: - a new - Gtk.Image- Return type: - Gtk.Widget- Creates a new - Gtk.Imagedisplaying the file filename. If the file isn’t found or can’t be loaded, the resulting- Gtk.Imagewill display a “broken image” icon. This function never returns- None, it always returns a valid- Gtk.Imagewidget.- If the file contains an animation, the image will contain an animation. - If you need to detect failures to load the file, use - GdkPixbuf.Pixbuf.new_from_file() to load the file yourself, then create the- Gtk.Imagefrom the pixbuf. (Or for animations, use- GdkPixbuf.PixbufAnimation.new_from_file()).- The storage type ( - Gtk.Image.get_storage_type()) of the returned image is not defined, it will be whatever is appropriate for displaying the file.
 - 
classmethod new_from_gicon(icon, size)[source]¶
- Parameters: - icon (Gio.Icon) – an icon
- size (int) – a stock icon size (Gtk.IconSize)
 - Returns: - a new - Gtk.Imagedisplaying the themed icon- Return type: - Creates a - Gtk.Imagedisplaying an icon from the current icon theme. If the icon name isn’t known, a “broken image” icon will be displayed instead. If the current icon theme is changed, the icon will be updated appropriately.- New in version 2.14. 
- icon (
 - 
classmethod new_from_icon_name(icon_name, size)[source]¶
- Parameters: - icon_name (strorNone) – an icon name orNone
- size (int) – a stock icon size (Gtk.IconSize)
 - Returns: - a new - Gtk.Imagedisplaying the themed icon- Return type: - Creates a - Gtk.Imagedisplaying an icon from the current icon theme. If the icon name isn’t known, a “broken image” icon will be displayed instead. If the current icon theme is changed, the icon will be updated appropriately.- New in version 2.6. 
- icon_name (
 - 
classmethod new_from_icon_set(icon_set, size)[source]¶
- Parameters: - icon_set (Gtk.IconSet) – aGtk.IconSet
- size (int) – a stock icon size (Gtk.IconSize)
 - Returns: - a new - Gtk.Image- Return type: - Creates a - Gtk.Imagedisplaying an icon set. Sample stock sizes are- Gtk.IconSize.MENU,- Gtk.IconSize.SMALL_TOOLBAR. Instead of using this function, usually it’s better to create a- Gtk.IconFactory, put your icon sets in the icon factory, add the icon factory to the list of default factories with- Gtk.IconFactory.add_default(), and then use- Gtk.Image.new_from_stock(). This will allow themes to override the icon you ship with your application.- The - Gtk.Imagedoes not assume a reference to the icon set; you still need to unref it if you own references.- Gtk.Imagewill add its own reference rather than adopting yours.- Deprecated since version 3.10: Use - Gtk.Image.new_from_icon_name() instead.
- icon_set (
 - 
classmethod new_from_pixbuf(pixbuf)[source]¶
- Parameters: - pixbuf ( - GdkPixbuf.Pixbufor- None) – a- GdkPixbuf.Pixbuf, or- None- Returns: - a new - Gtk.Image- Return type: - Gtk.Widget- Creates a new - Gtk.Imagedisplaying pixbuf. The- Gtk.Imagedoes not assume a reference to the pixbuf; you still need to unref it if you own references.- Gtk.Imagewill add its own reference rather than adopting yours.- Note that this function just creates an - Gtk.Imagefrom the pixbuf. The- Gtk.Imagecreated will not react to state changes. Should you want that, you should use- Gtk.Image.new_from_icon_name().
 - 
classmethod new_from_resource(resource_path)[source]¶
- Parameters: - resource_path ( - str) – a resource path- Returns: - a new - Gtk.Image- Return type: - Gtk.Widget- Creates a new - Gtk.Imagedisplaying the resource file resource_path. If the file isn’t found or can’t be loaded, the resulting- Gtk.Imagewill display a “broken image” icon. This function never returns- None, it always returns a valid- Gtk.Imagewidget.- If the file contains an animation, the image will contain an animation. - If you need to detect failures to load the file, use - GdkPixbuf.Pixbuf.new_from_file() to load the file yourself, then create the- Gtk.Imagefrom the pixbuf. (Or for animations, use- GdkPixbuf.PixbufAnimation.new_from_file()).- The storage type ( - Gtk.Image.get_storage_type()) of the returned image is not defined, it will be whatever is appropriate for displaying the file.- New in version 3.4. 
 - 
classmethod new_from_stock(stock_id, size)[source]¶
- Parameters: - stock_id (str) – a stock icon name
- size (int) – a stock icon size (Gtk.IconSize)
 - Returns: - a new - Gtk.Imagedisplaying the stock icon- Return type: - Creates a - Gtk.Imagedisplaying a stock icon. Sample stock icon names are- Gtk.STOCK_OPEN,- Gtk.STOCK_QUIT. Sample stock sizes are- Gtk.IconSize.MENU,- Gtk.IconSize.SMALL_TOOLBAR. If the stock icon name isn’t known, the image will be empty. You can register your own stock icon names, see- Gtk.IconFactory.add_default() and- Gtk.IconFactory.add().- Deprecated since version 3.10: Use - Gtk.Image.new_from_icon_name() instead.
- stock_id (
 - 
classmethod new_from_surface(surface)[source]¶
- Parameters: - surface ( - cairo.Surfaceor- None) – a- cairo.Surface, or- None- Returns: - a new - Gtk.Image- Return type: - Gtk.Widget- Creates a new - Gtk.Imagedisplaying surface. The- Gtk.Imagedoes not assume a reference to the surface; you still need to unref it if you own references.- Gtk.Imagewill add its own reference rather than adopting yours.- New in version 3.10. 
 - 
get_animation()[source]¶
- Returns: - the displayed animation, or - Noneif the image is empty- Return type: - GdkPixbuf.PixbufAnimationor- None- Gets the - GdkPixbuf.PixbufAnimationbeing displayed by the- Gtk.Image. The storage type of the image must be- Gtk.ImageType.EMPTYor- Gtk.ImageType.ANIMATION(see- Gtk.Image.get_storage_type()). The caller of this function does not own a reference to the returned animation.
 - 
get_gicon()[source]¶
- Returns: - gicon: - place to store a - Gio.Icon, or- None- size: - place to store an icon size ( - Gtk.IconSize), or- None- Return type: - (gicon: - Gio.Icon, size:- int)- Gets the - Gio.Iconand size being displayed by the- Gtk.Image. The storage type of the image must be- Gtk.ImageType.EMPTYor- Gtk.ImageType.GICON(see- Gtk.Image.get_storage_type()). The caller of this function does not own a reference to the returned- Gio.Icon.- New in version 2.14. 
 - 
get_icon_name()[source]¶
- Returns: - icon_name: - place to store an icon name, or - None- size: - place to store an icon size ( - Gtk.IconSize), or- None- Return type: - (icon_name: - str, size:- int)- Gets the icon name and size being displayed by the - Gtk.Image. The storage type of the image must be- Gtk.ImageType.EMPTYor- Gtk.ImageType.ICON_NAME(see- Gtk.Image.get_storage_type()). The returned string is owned by the- Gtk.Imageand should not be freed.- New in version 2.6. 
 - 
get_icon_set()[source]¶
- Returns: - icon_set: - location to store a - Gtk.IconSet, or- None- size: - location to store a stock icon size ( - Gtk.IconSize), or- None- Return type: - (icon_set: - Gtk.IconSet, size:- int)- Gets the icon set and size being displayed by the - Gtk.Image. The storage type of the image must be- Gtk.ImageType.EMPTYor- Gtk.ImageType.ICON_SET(see- Gtk.Image.get_storage_type()).- Deprecated since version 3.10: Use - Gtk.Image.get_icon_name() instead.
 - 
get_pixbuf()[source]¶
- Returns: - the displayed pixbuf, or - Noneif the image is empty- Return type: - GdkPixbuf.Pixbufor- None- Gets the - GdkPixbuf.Pixbufbeing displayed by the- Gtk.Image. The storage type of the image must be- Gtk.ImageType.EMPTYor- Gtk.ImageType.PIXBUF(see- Gtk.Image.get_storage_type()). The caller of this function does not own a reference to the returned pixbuf.
 - 
get_pixel_size()[source]¶
- Returns: - the pixel size used for named icons. - Return type: - int- Gets the pixel size used for named icons. - New in version 2.6. 
 - 
get_stock()[source]¶
- Returns: - stock_id: - place to store a stock icon name, or - None- size: - place to store a stock icon size ( - Gtk.IconSize), or- None- Return type: - (stock_id: - str, size:- int)- Gets the stock icon name and size being displayed by the - Gtk.Image. The storage type of the image must be- Gtk.ImageType.EMPTYor- Gtk.ImageType.STOCK(see- Gtk.Image.get_storage_type()). The returned string is owned by the- Gtk.Imageand should not be freed.- Deprecated since version 3.10: Use - Gtk.Image.get_icon_name() instead.
 - 
get_storage_type()[source]¶
- Returns: - image representation being used - Return type: - Gtk.ImageType- Gets the type of representation being used by the - Gtk.Imageto store image data. If the- Gtk.Imagehas no image data, the return value will be- Gtk.ImageType.EMPTY.
 - 
set_from_animation(animation)[source]¶
- Parameters: - animation ( - GdkPixbuf.PixbufAnimation) – the- GdkPixbuf.PixbufAnimation- Causes the - Gtk.Imageto display the given animation (or display nothing, if you set the animation to- None).
 - 
set_from_file(filename)[source]¶
- Parameters: - filename ( - stror- None) – a filename or- None- See - Gtk.Image.new_from_file() for details.
 - 
set_from_gicon(icon, size)[source]¶
- Parameters: - icon (Gio.Icon) – an icon
- size (int) – an icon size (Gtk.IconSize)
 - See - Gtk.Image.new_from_gicon() for details.- New in version 2.14. 
- icon (
 - 
set_from_icon_name(icon_name, size)[source]¶
- Parameters: - icon_name (strorNone) – an icon name orNone
- size (int) – an icon size (Gtk.IconSize)
 - See - Gtk.Image.new_from_icon_name() for details.- New in version 2.6. 
- icon_name (
 - 
set_from_icon_set(icon_set, size)[source]¶
- Parameters: - icon_set (Gtk.IconSet) – aGtk.IconSet
- size (int) – a stock icon size (Gtk.IconSize)
 - See - Gtk.Image.new_from_icon_set() for details.- Deprecated since version 3.10: Use - Gtk.Image.set_from_icon_name() instead.
- icon_set (
 - 
set_from_pixbuf(pixbuf)[source]¶
- Parameters: - pixbuf ( - GdkPixbuf.Pixbufor- None) – a- GdkPixbuf.Pixbufor- None- See - Gtk.Image.new_from_pixbuf() for details.
 - 
set_from_resource(resource_path)[source]¶
- Parameters: - resource_path ( - stror- None) – a resource path or- None- See - Gtk.Image.new_from_resource() for details.
 - 
set_from_stock(stock_id, size)[source]¶
- Parameters: - stock_id (str) – a stock icon name
- size (int) – a stock icon size (Gtk.IconSize)
 - See - Gtk.Image.new_from_stock() for details.- Deprecated since version 3.10: Use - Gtk.Image.set_from_icon_name() instead.
- stock_id (
 - 
set_from_surface(surface)[source]¶
- Parameters: - surface ( - cairo.Surfaceor- None) – a- cairo.Surfaceor- None- See - Gtk.Image.new_from_surface() for details.- New in version 3.10. 
 - 
set_pixel_size(pixel_size)[source]¶
- Parameters: - pixel_size ( - int) – the new pixel size- Sets the pixel size to use for named icons. If the pixel size is set to a value != -1, it is used instead of the icon size set by - Gtk.Image.set_from_icon_name().- New in version 2.6. 
 
- Handling button press events on a 
Property Details¶
- 
Gtk.Image.props.file¶
- Name: - file- Type: - str- Default Value: - None- Flags: - READABLE,- WRITABLE- Filename to load and display 
- 
Gtk.Image.props.gicon¶
- Name: - gicon- Type: - Gio.Icon- Default Value: - None- Flags: - READABLE,- WRITABLE- The - Gio.Icondisplayed in the- Gtk.Image. For themed icons, If the icon theme is changed, the image will be updated automatically.- New in version 2.14. 
- 
Gtk.Image.props.icon_name¶
- Name: - icon-name- Type: - str- Default Value: - None- Flags: - READABLE,- WRITABLE- The name of the icon in the icon theme. If the icon theme is changed, the image will be updated automatically. - New in version 2.6. 
- 
Gtk.Image.props.icon_set¶
- Name: - icon-set- Type: - Gtk.IconSet- Default Value: - None- Flags: - DEPRECATED,- READABLE,- WRITABLE- Icon set to display - Deprecated since version 3.10: Use - Gtk.Image- :icon-nameinstead.
- 
Gtk.Image.props.icon_size¶
- Name: - icon-size- Type: - int- Default Value: - 4- Flags: - READABLE,- WRITABLE,- EXPLICIT_NOTIFY- Symbolic size to use for stock icon, icon set or named icon 
- 
Gtk.Image.props.pixbuf¶
- Name: - pixbuf- Type: - GdkPixbuf.Pixbuf- Default Value: - None- Flags: - READABLE,- WRITABLE- A - GdkPixbuf.Pixbufto display
- 
Gtk.Image.props.pixbuf_animation¶
- Name: - pixbuf-animation- Type: - GdkPixbuf.PixbufAnimation- Default Value: - None- Flags: - READABLE,- WRITABLE- GdkPixbuf.PixbufAnimationto display
- 
Gtk.Image.props.pixel_size¶
- Name: - pixel-size- Type: - int- Default Value: - -1- Flags: - READABLE,- WRITABLE,- EXPLICIT_NOTIFY- The “pixel-size” property can be used to specify a fixed size overriding the - Gtk.Image- :icon-sizeproperty for images of type- Gtk.ImageType.ICON_NAME.- New in version 2.6. 
- 
Gtk.Image.props.resource¶
- Name: - resource- Type: - str- Default Value: - None- Flags: - READABLE,- WRITABLE- A path to a resource file to display. - New in version 3.8. 
- 
Gtk.Image.props.stock¶
- Name: - stock- Type: - str- Default Value: - None- Flags: - DEPRECATED,- READABLE,- WRITABLE- Stock ID for a stock image to display - Deprecated since version 3.10: Use - Gtk.Image- :icon-nameinstead.
- 
Gtk.Image.props.storage_type¶
- Name: - storage-type- Type: - Gtk.ImageType- Default Value: - Gtk.ImageType.EMPTY- Flags: - READABLE- The representation being used for image data 
- 
Gtk.Image.props.surface¶
- Name: - surface- Type: - cairo.Surface- Default Value: - None- Flags: - READABLE,- WRITABLE- A - cairo.Surfaceto display
- 
Gtk.Image.props.use_fallback¶
- Name: - use-fallback- Type: - bool- Default Value: - False- Flags: - READABLE,- WRITABLE,- EXPLICIT_NOTIFY- Whether the icon displayed in the - Gtk.Imagewill use standard icon names fallback. The value of this property is only relevant for images of type- Gtk.ImageType.ICON_NAMEand- Gtk.ImageType.GICON.- New in version 3.0. 
