- PyGTK - Drag and Drop
- PyGTK - Timeout
- PyGTK - Ruler Class
- PyGTK - Clipboard Class
- PyGTK - Calendar Class
- PyGTK - SpinButton Class
- PyGTK - DrawingArea Class
- PyGTK - Image Class
- PyGTK - Arrow Class
- PyGTK - Scrolledwindow Class
- PyGTK - Viewport Class
- PyGTK - ProgressBar Class
- PyGTK - Statusbar Class
- PyGTK - Paned Class
- PyGTK - TreeView Class
- PyGTK - AspectFrame Class
- PyGTK - Frame Class
- PyGTK - Notebook Class
- PyGTK - File Chooser Dialog
- PyGTK - Color Selection Dialog
- PyGTK - Font Selection Dialog
- PyGTK - AboutDialog Class
- PyGTK - MessageDialog Class
- PyGTK - Dialog Class
- PyGTK - Scrollbar Class
- PyGTK - Scale Class
- PyGTK - Range Class
- PyGTK - Adjustment Class
- PyGTK - Toolbar Class
- PyGTK - MenuBar, Menu & MenuItem
- PyGTK - RadioButton Class
- PyGTK - CheckButton Class
- PyGTK - ToggleButton Class
- PyGTK - ComboBox Class
- PyGTK - Layout Class
- PyGTK - EventBox Class
- PyGTK - Alignment Class
- PyGTK - ButtonBox Class
- PyGTK - Box Class
- PyGTK - Containers
- PyGTK - Event Handling
- PyGTK - Signal Handling
- PyGTK - Entry Class
- PyGTK - Label CLass
- PyGTK - Button Class
- PyGTK - Window Class
- PyGTK - Important Classes
- PyGTK - Hello World
- PyGTK - Environment
- PyGTK - Introduction
- PyGTK - Home
PyGTK Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
PyGTK - Image Class
This class is also inherited from the gtk.Misc class. The object of the gtk.Image class displays an image. Usually, the image is to be loaded from a file in a pixel buffer representing gtk.gdk.Pixbuf class. Instead a convenience function set_from_file() is commonly used to display image data from file in a gk.Image widget.
The easiest way to create the gtk.Image object is to use the following constructor −
img = gtk.Image()
The following are the methods of the gtk.Image class −
Image.set_from_file() − This sets the image data from the contents of the file.
Image.set_from_pixbuf() − This sets the image data from pixmap in which the image data is loaded for offscreen manipulation.
Image.set_from_pixbuf() − This sets the image data using pixbuf which is an object containing the data that describes an image using cpent side resources.
Image.set_from_stock() − This sets the image data from the stock item identified by stock_id.
Image.clear() − This removes the current image.
Image.set_from_image() − This sets the image data from a cpent-side image buffer in the pixel format of the current display. If the image is None, the current image data will be removed.
Example
In the following program, the gtk.Image object is obtained from an image file. It is further added in the toplevel window.
import gtk class PyApp(gtk.Window): def __init__(self): super(PyApp, self).__init__() self.set_title("PyGtk Image demo") self.set_size_request(300, 200) self.set_position(gtk.WIN_POS_CENTER) image1 = gtk.Image() image1.set_from_file("python.png") self.add(image1) self.connect("destroy", gtk.main_quit) self.show_all() PyApp() gtk.main()
The above code will generate the following output −
Advertisements