Python Turtle Wait for Click
04:55 26 Sep 2016

I'd like to be able to pause and contemplate each step of this program, and move on to the next step by clicking the screen. Initially I tried adding a bunch of events, but then my brain kicked in and reminded me that this is not a procedural program and the first binding would remain the only one(!). Main program below, any help much appreciated.

  def tree(self, branchLen):
    if branchLen > 5:
      self.screen.onscreenclick(lambda x,y: self.t.forward(branchLen))
      self.screen.onscreenclick(lambda x,y: self.t.right(20))
      self.tree(branchLen-15)
      self.screen.onscreenclick(lambda x,y: self.t.left(40))
      self.tree(branchLen-15)
      self.screen.onscreenclick(lambda x,y: self.t.right(20))
      self.screen.onscreenclick(lambda x,y: self.t.backward(branchLen))

import turtle

class Tree(object):
  def __init__(self):
    self.t = turtle.Turtle()
    self.screen = turtle.Screen()

    self.t.left(90)
    self.t.up()
    self.t.backward(100)
    self.t.down()
    self.t.color("green")
    self.tree(75)

  def tree(self, branchLen):
    if branchLen > 5:
      self.t.forward(branchLen)
      self.t.right(20)
      self.tree(branchLen-15)
      self.t.left(40)
      self.tree(branchLen-15)
      self.t.right(20)
      self.t.backward(branchLen)

tree = Tree()
python recursion events turtle-graphics python-turtle