"file"WriteA filename containing the image data. Default value:
None"gicon"Read-WriteThe GIcon displayed in the GtkImage. For themed icons,
If the icon theme is changed, the image will be updated automatically.
Available in GTK 2.14 and above."icon-name"Read-WriteThe name of the icon in the icon theme. If the icon
theme is changed, the image will be updated automatically. Default value:
None. Available in GTK 2.6 and above."icon-set"Read-Writethe gtk.IconSet to
display"icon-size"Read-Writethe size to use for a stock icon, named icon or icon
set. Allowed values: >= 0. Default value: 4"image"Read-Writea gtk.gdk.Image to
display"mask"Read-Writea bitmap gtk.gdk.Pixmap to
use with a gtk.gdk.Image or a
gtk.gdk.Pixmap"pixbuf"Read-Writethe gtk.gdk.Pixbuf
to display"pixbuf-animation"Read-Writethe gtk.gdk.PixbufAnimation
to display"pixel-size"Read-Writea fixed size overriding the "icon-size" property for
images of type gtk.IMAGE_ICON_NAME. Allowed values: >=
-1. Default value: -1. Available in GTK+ 2.6 and above."pixmap"Read-Writea gtk.gdk.Pixmap to
display"stock"Read-Writethe stock ID for a stock image to display. Default
value: None"storage-type"Readthe type of the image data; one of the :
gtk.IMAGE_EMPTY, gtk.IMAGE_PIXMAP,
gtk.IMAGE_IMAGE, gtk.IMAGE_PIXBUF,
gtk.IMAGE_STOCK, gtk.IMAGE_ICON_SET or
gtk.IMAGE_ANIMATION
gtk.Image Style Propertiesgtk.Widget Style Propertiesgtk.Image Signal Prototypesgobject.GObject Signal Prototypesgtk.Object Signal Prototypesgtk.Widget Signal PrototypesDescriptionThe gtk.Image widget
displays an image. Various kinds of objects can be displayed as an image;
usually, you would load a gtk.gdk.Pixbuf
("pixel buffer") from a file, and then display it. The convenience method
set_from_file()
will read the file and automatically create a pixbuf that is added to the
gtk.Image
widget. 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 gtk.gdk.pixbuf_new_from_file(),
then add it to the gtk.Image with the
set_from_pixbuf()
method. The image file may contain an animation; if so, the gtk.Image will
display an animation (gtk.gdk.PixbufAnimation)
instead of a static image.gtk.Image is a
subclass of gtk.Misc, which
implies that you can align it (center, left, right) and add padding to it,
using the gtk.Misc methods.
gtk.Image is a
"no window" widget (has no gtk.gdk.Window of
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.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 program allows you to
convert an image into a C variable declaration, which can then be loaded
into a gtk.gdk.Pixbuf using
the gtk.gdk.pixbuf_new_from_inline()
function. This can also be used in PyGTK by modifying the
output using an editor or the sed command as
follows:
gdk-pixbuf-csource imagefile | \
sed -n -e 's/{/[/' -e 's/};/]/' -e '/".*"/p' >outfile
You can edit outfile into a Python file where
it will be evaluated to a list containing a string. The string can be used
directly with the gtk.gdk.pixbuf_new_from_inline()
function to create a pixbuf that can be used in a gtk.Image.Constructorgtk.ImageReturns :a newly created gtk.Image
widget.Creates a new empty gtk.Image
widget.Methodsgtk.Image.set_from_pixmapset_from_pixmappixmapmaskpixmap :a gtk.gdk.Pixmapmask :a bitmap gtk.gdk.Pixmap or
NoneThe set_from_pixmap() method sets the
image data from pixmap using
mask.gtk.Image.set_from_imageset_from_imagegdk_imagemaskgdk_image :a gtk.gdk.Image or
Nonemask :a bitmap gtk.gdk.Pixmap or
NoneThe set_from_image() method sets the
image data from image using
mask. A gtk.gdk.Image is a
client-side image buffer in the pixel format of the current display. If
image is None the current image
data will be removed.gtk.Image.set_from_fileset_from_filefilenamefilename :a filename or
NoneThe set_from_file() method sets the
image data from the contents of the file named
filename. If the file isn't found or can't be loaded,
the resulting gtk.Image will
display a "broken image" icon. This function never returns None, it always
returns a valid gtk.Image widget. If
the file contains an animation, the image will contain an animation. If
filename is None the current image
data will be removed.If you need to detect failures to load the file, use gtk.gdk.pixbuf_new_from_file()
to load the file yourself, then create the gtk.Image from the
pixbuf. (Or for animations, use the gtk.gdk.PixbufAnimation()
constructor.gtk.Image.set_from_pixbufset_from_pixbufpixbufpixbuf :a gtk.gdk.Pixbuf or
NoneThe set_from_pixbuf() method sets the
image data using pixbuf. Note that this function just
creates an gtk.Image from
pixbuf. The gtk.Image created
will not react to state changes. Should you want that, you should use the
set_from_icon_set()
method If pixbuf is None the
current image data will be removed.gtk.Image.set_from_stockset_from_stockstock_idsizestock_id :a stock icon namesize :a stock icon sizeThe set_from_stock() method sets the
image data from the stock item identified by
stock_id. Sample stock icon names are
gtk.STOCK_OPEN and gtk.STOCK_OK.
Stock icon sizes are gtk.ICON_SIZE_MENU,
gtk.ICON_SIZE_SMALL_TOOLBAR,
gtk.ICON_SIZE_LARGE_TOOLBAR,
gtk.ICON_SIZE_BUTTON,
gtk.ICON_SIZE_DND and
gtk.ICON_SIZE_DIALOG. If the stock icon name isn't known,
a "broken image" icon will be displayed instead. You can register your own
stock icon names, see the gtk.IconFactory.add_default()
and gtk.IconFactory.add()
methods.The stock icons are described in the Stock Items reference.gtk.Image.set_from_icon_setset_from_icon_seticon_setsizeicon_set :a gtk.IconSetsize :a stock icon sizeThe set_from_icon_set() method sets the
image data from icon_set with the size specified by
size. Stock icon sizes are
gtk.ICON_SIZE_MENU,
gtk.ICON_SIZE_SMALL_TOOLBAR,
gtk.ICON_SIZE_LARGE_TOOLBAR,
gtk.ICON_SIZE_BUTTON,
gtk.ICON_SIZE_DND and
gtk.ICON_SIZE_DIALOG.gtk.Image.set_from_animationset_from_animationanimationanimation :the gtk.gdk.PixbufAnimationThe set_from_animation() method sets
the image data from animation.gtk.Image.get_storage_typeget_storage_typeReturns :the type of the image representation being
usedThe get_storage_type() method gets the
type of representation being used by the gtk.Image to store
image data. If the gtk.Image has no
image data, the return value will be gtk.IMAGE_EMPTY. The
image type is one of: gtk.IMAGE_EMPTY,
gtk.IMAGE_PIXMAP, gtk.IMAGE_IMAGE,
gtk.IMAGE_PIXBUF, gtk.IMAGE_STOCK,
gtk.IMAGE_ICON_SET or
gtk.IMAGE_ANIMATION.gtk.Image.get_pixmapget_pixmapReturns :a tuple containing the pixmap (or
None) and the mask (or
None)The get_pixmap() method returns a tuple
containing the pixmap and mask being displayed by the gtk.Image. Either or
both the pixmap and mask may be None. If the storage type
of the image is not either gtk.IMAGE_EMPTY or
gtk.IMAGE_PIXMAP the ValueError exception will be
raised.gtk.Image.get_imageget_imageReturns :a tuple containing a gtk.gdk.Image and a
mask bitmapThe get_image() method returns a tuple
containing the gtk.gdk.Image and
mask being displayed by the gtk.Image. One or
both of the gtk.gdk.Image and
mask may be None. If the storage type of the image is not
either of gtk.IMAGE_EMPTY or
gtk.IMAGE_IMAGE the ValueError exception will be
raised.gtk.Image.get_pixbufget_pixbufReturns :the displayed pixbuf, or
None if the image is emptyThe get_pixbuf() method gets the gtk.gdk.Pixbuf being
displayed by the gtk.Image. The return
value may be None if no image data is set. If the storage type of the image
is not either gtk.IMAGE_EMPTY or
gtk.IMAGE_PIXBUF the ValueError exception will be
raised.gtk.Image.get_stockget_stockReturns :a tuple containing the stock icon name and the
stock icon size of the image dataThe get_stock() method returns a tuple
containing the stock icon identifier (may be None) and
size being displayed by the gtk.Image. The size
will be one of: gtk.ICON_SIZE_MENU,
gtk.ICON_SIZE_SMALL_TOOLBAR,
gtk.ICON_SIZE_LARGE_TOOLBAR,
gtk.ICON_SIZE_BUTTON,
gtk.ICON_SIZE_DND or
gtk.ICON_SIZE_DIALOG. If the storage type of the image is
not either gtk.IMAGE_EMPTY or
gtk.IMAGE_STOCK the ValueError exception will be
raised.gtk.Image.get_icon_setget_icon_setReturns :a tuple containing a gtk.IconSet and a
stock icon sizeThe get_icon_set() method returns a
tuple containing the icon set (may be None) and size
being displayed by the gtk.Image. The size
will be one of: gtk.ICON_SIZE_MENU,
gtk.ICON_SIZE_SMALL_TOOLBAR,
gtk.ICON_SIZE_LARGE_TOOLBAR,
gtk.ICON_SIZE_BUTTON,
gtk.ICON_SIZE_DND or
gtk.ICON_SIZE_DIALOG. If the storage type of the image is
not either gtk.IMAGE_EMPTY or
gtk.IMAGE_ICON_SET the ValueError exception will be
raised.gtk.Image.get_animationget_animationReturns :the displayed animation, or
None if the image is emptyThe get_animation() method gets the
gtk.gdk.PixbufAnimation
(may be None if there is no image data) being displayed by the gtk.Image. If the
storage type of the image is not either gtk.IMAGE_EMPTY
or gtk.IMAGE_ANIMATION the ValueError exception will be
raised.gtk.Image.get_icon_nameget_icon_nameReturns :a 2-tuple containing the name and size of the
displayed icon.This method is available in PyGTK 2.6 and above.The get_icon_name() method returns a
2-tuple containing the values of the "icon-name" and "icon-size" properties
respectively if the "icon-name" property is not None. If
the "icon-name" property is None the 2-tuple returned
will be:
(None, <enum GTK_ICON_SIZE_INVALID of type GtkIconSize>)
gtk.Image.set_from_icon_nameset_from_icon_nameicon_namesizeicon_name :an icon namesize :a stock icon sizeThis method is available in PyGTK 2.6 and above.The set_from_icon_name() method sets
the "icon-name" and "icon-size" properties to the values of
icon_name and size
respectively. icon_name should be the name of an icon
in the current icon theme. If 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.gtk.Image.set_pixel_sizeset_pixel_sizepixel_sizepixel_size :the new pixel size to be used for named
iconsThis method is available in PyGTK 2.6 and above.The set_pixel_size() method sets the
"pixel-size" property to the value specified by
pixel_size. If the pixel size is set to a value != -1
the "pixel-size" property is used instead of the icon size set by the set_from_icon_name()
method.gtk.Image.get_pixel_sizeget_pixel_sizeReturns :the pixel size used for named
icons.This method is available in PyGTK 2.6 and above.The get_pixel_size() method returns the
value of the "pixel-size" property which specifies the pixel size to be used
for named icons.gtk.Image.clearclearThis method is available in PyGTK 2.8 and above.The clear() method removes the current
image, if any, and resets the "storage-type", "mask" and "icon-size"
properties. One of the "file", "icon-name", "icon-set", "image", "pixbuf",
"pixbuf-animation", "pixmap" or "stock" will be reset if there was an
existing image.gtk.Image.set_from_giconset_from_giconiconsizeicon :an iconsize :an icon sizeThis method is available in PyGTK 2.14 and above.
For the set_from_gicon() method see
gtk.image_new_from_gicon()
for details.
Functionsgtk.image_new_from_stockgtk.image_new_from_stockstock_idsizestock_id :a stock icon namesize :an integer representing an icon
sizeReturns :a new gtk.Image
displaying the stock iconThe gtk.image_new_from_stock() function
returns a new gtk.Image displaying
the stock icon specified by stock_id with the
specified size. Sample stock icon names are
gtk.STOCK_OPEN, gtk.STOCK_OK - see the
set_from_stock()
method for detailed information on the PyGTK stock icons.
. Sample stock sizes are gtk.ICON_SIZE_MENU,
gtk.ICON_SIZE_SMALL_TOOLBAR - see the gtk.icon_size_lookup() function for more detail. If the stock icon name isn't
known, a "broken image" icon will be displayed instead. You can register
your own stock icon names, see the gtk.IconFactory.add_default()
and gtk.IconFactory.add()
methods.gtk.image_new_from_icon_setgtk.image_new_from_icon_seticon_setsizeicon_set :a gtk.IconSet
objectsize :an integer representing an icon
sizeReturns :a new gtk.Image
objectThe gtk.image_new_from_icon_set() function
returns a new gtk.Image created
from the gtk.IconSet
specified by icon_set with the specified
size. Sample stock sizes are
gtk.ICON_SIZE_MENU,
gtk.ICON_SIZE_SMALL_TOOLBAR - see the gtk.icon_size_lookup()
function for more detail. 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 the add_default()
method, and then use the gtk.image_new_from_stock()
function. This will allow themes to override the icon you ship with your
application.gtk.image_new_from_animationgtk.image_new_from_animationanimationanimation :a gtk.gdk.PixbufAnimation
objectReturns :a new gtk.Image
objectThe gtk.image_new_from_animation() function
returns a new gtk.Image object
containing the gtk.gdk.PixbufAnimation
specified by animation.gtk.image_new_from_icon_namegtk.image_new_from_icon_nameicon_namesizeicon_name :an icon namesize :a stock icon sizeReturns :a new gtk.Image
widget.This function is available in PyGTK 2.6 and above.The gtk.image_new_from_icon_name() function
returns a new gtk.Image object
displaying the named theme icon specified by
icon_name with the icon size specified by
size. 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. The "icon-name" and "icon-size"
properties are also set by this function.gtk.image_new_from_pixmapgtk.image_new_from_pixmappixmapmaskpixmap :a gtk.gdk.Pixmapmask :the bitmap that is the transparency mask.Returns :a new gtk.Image
widget.This function is available in PyGTK 2.12 and above.The gtk.image_new_from_pixmap() function
returns a new gtk.Image object
displaying pixmap with a mask. A gtk.gdk.Pixmap
is a server-side image buffer in the pixel format of the current display.gtk.image_new_from_imagegtk.image_new_from_imageimagemaskimage :a gtk.gdk.Imagemask :the bitmap that is the transparency mask.Returns :a new gtk.Image
widget.This function is available in PyGTK 2.12 and above.The gtk.image_new_from_image() function
returns a new gtk.Image object
displaying an image with a mask. A gtk.gdk.Image
is a client-side image buffer in the pixel format of the current display.gtk.image_new_from_filegtk.image_new_from_filefilenamefilename :a filenameReturns :a new gtk.Image
widget.This function is available in PyGTK 2.12 and above.The gtk.image_new_from_file() function
returns a new gtk.Image object
displaying the file filename. If the file isn't found or can't be loaded,
the resulting gtk.Image
will display a "broken image" icon. This function never returns None,
it always returns a valid gtk.Image
widget.If the file contains an animation, the image will contain an animation.If you need to detect failures to load the file, use gtk.gdk.pixbuf_new_from_file
to load the file yourself, then create the gtk.Image
from the pixbuf. (Or for animations, use gtk.gdk.PixbufAnimation.
The storage type (get_storage_type)
of the returned image is not defined, it will be whatever is appropriate
for displaying the file.gtk.image_new_from_pixbufgtk.image_new_from_pixbufpixbufpixbuf :a gtk.gdk.PixbufReturns :a new gtk.Image
widget.This function is available in PyGTK 2.12 and above.The gtk.image_new_from_pixbuf() function
returns a new gtk.Image object
displaying pixbufNote that this function just creates a gtk.Image from the pixbuf. The
gtk.Image
created will not react to state changes. Should you want that, you should use
gtk.image_new_from_icon_set
gtk.image_new_from_gicongtk.image_new_from_gicongiconsizegicon :a gio.Iconsize :a stock icon size.
Returns :a new gtk.Image
displaying the themed icon.This function is available in PyGTK 2.14 and above.The gtk.image_new_from_pixbuf() function returns
a new gtk.Image
displaying 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.