User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 363,779 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,496 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser:
Apr 22nd, 2008
Views: 1,301
The module pyglet leans on OpenGL for graphics and is used in the scientific community together with Python. This short code snippet shows you how to use it to display an animated GIF file. The download is free, so give it a try. You don't have to download OpenGL to use pyglet.
python Syntax | 4 stars
  1. # load and show an animated gif file using module pyglet
  2. # download module pyglet from: http://www.pyglet.org/download.html
  3. # the animated dinosaur-07.gif file is in the public domain
  4. # download from http://www.gifanimations.com
  5. # tested with Python2.5 and pyglet1.1a2 by vegaseat 22apr2008
  6.  
  7. import pyglet
  8.  
  9. # pick an animated gif file you have in the working directory
  10. ag_file = "dinosaur-07.gif"
  11. animation = pyglet.resource.animation(ag_file)
  12. sprite = pyglet.sprite.Sprite(animation)
  13.  
  14. # create a window and set it to the image size
  15. win = pyglet.window.Window(width=sprite.width, height=sprite.height)
  16.  
  17. # set window background color = r, g, b, alpha
  18. # each value goes from 0.0 to 1.0
  19. green = 0, 1, 0, 1
  20. pyglet.gl.glClearColor(*green)
  21.  
  22. @win.event
  23. def on_draw():
  24. win.clear()
  25. sprite.draw()
  26.  
  27. pyglet.app.run()
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 10:38 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC