Desde que você adicionou o GTK à sua pergunta, o exemplo e a documentação pode ser encontrado no tutorial do PyGTK 2.0 no < a href="http://www.pygtk.org/pygtk2tutorial/sec-Images.html"> Capítulo 9. Widgets Diversos .
Um exemplo de código usando .gif
para os botões:
#!/usr/bin/env python
# example images.py
import pygtk
pygtk.require('2.0')
import gtk
class ImagesExample:
# when invoked (via signal delete_event), terminates the application.
def close_application(self, widget, event, data=None):
gtk.main_quit()
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)
window.set_border_width(10)
window.show()
# a horizontal box to hold the buttons
hbox = gtk.HBox()
hbox.show()
window.add(hbox)
pixbufanim = gtk.gdk.PixbufAnimation("goalie.gif")
image = gtk.Image()
image.set_from_animation(pixbufanim)
image.show()
# a button to contain the image widget
button = gtk.Button()
button.add(image)
button.show()
hbox.pack_start(button)
button.connect("clicked", self.button_clicked, "1")
image = gtk.Image()
image.set_from_file("soccerball.gif")
image.show()
# a button to contain the image widget
button = gtk.Button()
button.add(image)
button.show()
hbox.pack_start(button)
button.connect("clicked", self.button_clicked, "2")
def main():
gtk.main()
return 0
if __name__ == "__main__":
ImagesExample()
main()
RESPOSTA ORIGINAL
Você pode usar PyQt com o Widget QMovie () para reproduzir um gif animado. Abaixo um exemplo que encontrei anteriormente.
Exemplo de Programação GUI em Python | DaniWeb 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
self.movie_screen.setSizePolicy(QSizePolicy.Expanding,
QSizePolicy.Expanding)
self.movie_screen.setAlignment(Qt.AlignCenter)
main_layout = QVBoxLayout()
main_layout.addWidget(self.movie_screen)
self.setLayout(main_layout)
# use an animated gif file you have in the working folder
# or give the full file path
movie = QMovie("AG_Dog.gif", QByteArray(), self)
movie.setCacheMode(QMovie.CacheAll)
movie.setSpeed(100)
self.movie_screen.setMovie(movie)
movie.start()
app = QApplication(sys.argv)
player = MoviePlayer()
player.show()
sys.exit(app.exec_())