The following PyGTK code displays a PNG file in a window.
Is there a simpler or better way of displaying the PNG file, like, by using a gtk.DrawingArea? For example, how do you resize the file?
import gtk
import pygtk
pygtk.require('2.0')
class Gui:
def __init__(self):
# Create an Image object for a PNG file.
file_name = "file.png"
pixbuf = gtk.gdk.pixbuf_new_from_file(file_name)
pixmap, mask = pixbuf.render_pixmap_and_mask()
image = gtk.Image()
image.set_from_pixmap(pixmap, mask)
# Create a window.
window = gtk.Window()
window.set_title("PNG file")
window.connect("destroy", gtk.main_quit)
# Show the PNG file in the window.
window.add(image)
window.show_all()
if __name__ == "__main__":
Gui()
gtk.main()
Acknowledgments: I created the above code using code from other people on the web.