You are reading an old version of the documentation (v1.4.0). For the latest version see

Previous topic

event_handling example code:

Next topic

event_handling example code:

This Page

event_handling example code: pong_gtk.pyΒΆ

[source code]

#!/usr/bin/env python

from __future__ import print_function

# For detailed comments on animation and the techniques used here, see
# the wiki entry
import time

import gtk, gobject

import matplotlib

import matplotlib.pyplot as plt
import pipong

fig, ax = plt.subplots()
canvas = ax.figure.canvas

def start_anim(event):
#    gobject.idle_add(animation.draw,animation)

animation = pipong.Game(ax)
start_anim.cid = canvas.mpl_connect('draw_event', start_anim)

tstart = time.time()
plt.grid() # to ensure proper background restore
print('FPS:' , animation.cnt/(time.time()-tstart))

Keywords: python, matplotlib, pylab, example, codex (see Search examples)