Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am developing Discvur, a simple Imgur viewer, for the Ubuntu App Showdown. Therefore I use quickly + Glade + Gtk + Python. PyGObject instead of PyGtk would be highly appreciated. I would like to display some animated gifs in my program.

What I tried was inserting a viewport, then an image, and then in the 'Edit Image' field I selected a gif animation (in my case "../media/akO1i.gif"). When I run my app, the gif is displayed but it is not moving (I only see the first frame).

Is it possible to show animated gifs in my app? What is the best and/or easiest way to do it: use the image widget, or a WebKit field, or something else?

share|improve this question
up vote 2 down vote accepted

Since you've added GTK to your question, example and documentation can be found at the PyGTK 2.0 Tutorial on the Chapter 9. Miscellaneous Widgets.

A code sample using .gif for buttons:

#!/usr/bin/env python

# example

import pygtk
import gtk

class ImagesExample:
    # when invoked (via signal delete_event), terminates the application.
    def close_application(self, widget, event, data=None):
        return False

    # is invoked when the button is clicked.  It just prints a message.
    def button_clicked(self, widget, data=None):
        print "button %s clicked" % data

    def __init__(self):
        # create the main window, and attach delete_event signal to terminating
        # the application
        window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        window.connect("delete_event", self.close_application)

        # a horizontal box to hold the buttons
        hbox = gtk.HBox()

        pixbufanim = gtk.gdk.PixbufAnimation("goalie.gif")
        image = gtk.Image()
        # a button to contain the image widget
        button = gtk.Button()
        button.connect("clicked", self.button_clicked, "1")

        image = gtk.Image()
        # a button to contain the image widget
        button = gtk.Button()
        button.connect("clicked", self.button_clicked, "2")

def main():
    return 0

if __name__ == "__main__":


You can use PyQt with the QMovie() widget to play an animated gif. Bellow an example that I've found earlier.

Example from Python GUI Programming | DaniWeb web-site:

# use PyQt's QMovie() widget to play an animated gif
# tested with PyQt4.4 and Python 2.5
# also tetsed with PyQt4.5 and Python 3.0
# vegaseat

import sys
# expect minimal namespace conflicts
from PyQt4.QtCore import *
from PyQt4.QtGui import * 

class MoviePlayer(QWidget):
    def __init__(self, parent=None): 

    QWidget.__init__(self, parent)
    # setGeometry(x_pos, y_pos, width, height)
    self.setGeometry(200, 200, 400, 300)
    self.setWindowTitle("QMovie to show animated gif")

    # set up the movie screen on a label
    self.movie_screen = QLabel()
    # expand and center the label

    main_layout = QVBoxLayout()

    # use an animated gif file you have in the working folder
    # or give the full file path
    movie = QMovie("AG_Dog.gif", QByteArray(), self)

app = QApplication(sys.argv)
player = MoviePlayer()
share|improve this answer
Thank you but I would prefer to stay with Gtk since I already started using and learning it. You answer is probably excellent for other people. – Agmenor Jun 23 '12 at 17:36
You didn't mentioned GTK before :) Just added an update to the top of my answer with an example, link to tutorials and documentation. – Zuul Jun 23 '12 at 17:53
This worked perfectly. Thank you for the script and for the link to the tutorial. – Agmenor Jun 23 '12 at 18:06
Could you maybe give me some more information about how to do it with PyGObject instead of PyGtk? I did from gi.repository import Gdk but the package "PixbufAnimation" is not in there. – Agmenor Jun 23 '12 at 18:51
Sure, here's a link to documentation and examples, and a link to Porting PyGTK to PyGObject. – Zuul Jun 23 '12 at 20:07

This is the code I finally wrote, thanks to Zuul's help. It is more specific to PyGObject, the tool that is used in Quickly:

from gi.repository import Gtk, GdkPixbuf
#This is specific to my app Discvur developed in Quickly:
from discvur_lib.discvurconfig import get_data_file


    self.viewport = self.builder.get_object("viewport")
    path = get_data_file() + "/media/akO1i.gif"
    print path
    self.pixbufanim = GdkPixbuf.PixbufAnimation.new_from_file(path)
    print self.pixbufanim
    self.image = Gtk.Image()
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.