title: Window shows previous frame when a key is pressed
body: <p>I've created a simple script that shows a square moving to the left:</p>
  
  <pre><code>import pyglet
  
  window = pyglet.window.Window(800, 600)
  
  x = 0
  y = 250
  width = 100
  height = 100
  
  
  def update(time):
      global x
  
      window.clear()
      pyglet.graphics.draw(4, pyglet.gl.GL_QUADS, ('v2f', [x, y, x, y+height, x+width, y+height, x+width, y]))
      x += 10
  
  
  pyglet.clock.schedule_interval(update, 1/10)
  
  pyglet.app.run()
  </code></pre>
  
  <p>The square is rendered correctly when there is no keyboard input, but whenever I press a key, it seems like the window is cleared and the previous frame gets rendered again. I solved the problem by splitting the update function and by using the <code>on_key_press()</code> function:</p>
  
  <pre><code>@window.event
  def on_key_press(symbol, modifiers):
      draw()
  
  
  def update(time):
      global x
      x += 10
      draw()
  
  
  def draw():
      window.clear()
      pyglet.graphics.draw(4, pyglet.gl.GL_QUADS, ('v2f', [x, y, x, y + height, x + width, y + height, x + width, y]))
  </code></pre>
  
  <p>But I don't think is the right way to solve the problem, because I'm rendering the square two times in one frame. You can see what the problem is over here: <a href="https://youtu.be/cIwuLYuLWtY" rel="nofollow noreferrer">https://youtu.be/cIwuLYuLWtY</a>.</p>