I have two onclick functions in my program, I want the first one to run 3 times and then stop permanently, and then the second one to run 5 times and stop permanently. How could I do that? I tried to use a counter to count the number of clicks but I can't figure out how to make that work.
Here is my code:
import turtle     
import random        
wn = turtle.Screen()      
wn.bgcolor('lightblue')
svea = turtle.Turtle()
sample=[1,2,3]
click_count=0
def square(t,size,r,g,b,x,y,z,click_count):
  if click_count==3:
    quit()
  else:
    t.pencolor(x,y,z)
    t.begin_fill()
    for i in range(4):
      t.forward(size)
      t.right(90)
    t.fillcolor(r,g,b)
    t.end_fill()
def triangle(t,size,r,g,b,x,y,z):
  t.pencolor(x,y,z)
  t.begin_fill()
  for i in range(3):      # repeat four times
    t.forward(size)
    t.left(120)
  t.fillcolor(r,g,b)
  t.end_fill()
def rectangle(t,size,r,g,b,x,y,z):
  t.pencolor(x,y,z)
  t.begin_fill()
  for i in range(2):      # repeat four times
    t.forward(size)
    t.left(90)
    t.forward(size*1.25)
    t.left(90)
  t.fillcolor(r,g,b)
  t.end_fill()
def drawOnClick(x,y):
  wn.onclick(None)
  size=random.randrange(50,150)
  svea.up()
  svea.goto(x,y)
  svea.down()
  square(svea,size,random.randrange(0,255),random.randrange(0,255),random.randrange(0,255),random.randrange(0,255),random.randrange(0,255),random.randrange(0,255),random.randint(0,3))
  triangle(svea,size,random.randrange(0,255),random.randrange(0,255),random.randrange(0,255),random.randrange(0,255),random.randrange(0,255),random.randrange(0,255))
  svea.up()
  svea.goto(x+(size*0.4),y-size)
  svea.down()
  rectangle(svea,size/4,random.randrange(0,255),random.randrange(0,255),random.randrange(0,255),random.randrange(0,255),random.randrange(0,255),random.randrange(0,255))
  svea.up()
  svea.goto(x+(size*0.15),y-(size*0.15))
  svea.down()
  square(svea,size/5,random.randrange(0,255),random.randrange(0,255),random.randrange(0,255),random.randrange(0,255),random.randrange(0,255),random.randrange(0,255),2)
  svea.up()
  svea.goto(x+(size*0.65),y-(size*0.15))
  svea.down()
  square(svea,size/5,random.randrange(0,255),random.randrange(0,255),random.randrange(0,255),random.randrange(0,255),random.randrange(0,255),random.randrange(0,255),2)
  wn.onclick(drawOnClick)
  #click_count+=1
  #if click_count==3:
    #quit()
def drawOnClick2(x,y):
  size=random.randrange(10,20)
  svea.begin_fill()
  svea.up()
  svea.goto(x,y)
  svea.down()
  svea.circle(size)
  svea.right(90)
  svea.forward(size*2)
  svea.right(45)
  svea.forward(size*2)
  svea.right(180)
  svea.forward(size*2)
  svea.right(90)
  svea.forward(size*2)
  svea.right(180)
  svea.forward(size*2)
  svea.right(45)
  svea.forward(size)
  svea.right(90)
  svea.forward(size*1.5)
  svea.right(180)
  svea.forward(size*3)
  svea.right(180)
#wn.onclick(drawOnClick2)
wn.onclick(drawOnClick)
#wn.onclick(None)
  
 # wn.exitonclick()
				
                        
I'm going to suggest a simple list of event handler functions that you
pop()each time you restore the event handler at the end of the event handler function. Seeonclick_functionsin the following rewrite of your code:This should make it simple to change the number of calls to each event handler function and add new ones.