def release_handler(x, y): global state turtle.onrelease(None) # disable until click turtle.ondrag(None) # disable competing handler turtle.onclick(click_handler) # watch for click event onmove(screen, move_handler) # dragging is now motion until click state = MOVING
def click_handler(x, y): global state turtle.onclick(None) # disable until release onmove(screen, None) # disable competing handler turtle.onrelease(release_handler) # watch for release event turtle.ondrag(drag_handler) # motion is now dragging until release state = DRAGGING
def main(): t.speed(20) t.shapesize(1000, 1000) t.up() t.goto(1000, 0) t.ht() t.onkey(showTurtle, "a") t.listen() t.onclick(getPos) t.onrelease(hideTurtle)
# turtle. onclick(fun, btn=1, add=None) # fun – a function with two arguments which will be called with the coordinates of the clicked point on the canvas # num – number of the mouse-button, defaults to 1 (left mouse button) # add – True or False – if True, a new binding will be added, otherwise it will replace a former binding # Bind fun to mouse-click events on this turtle. If fun is None, existing bindings are removed def glow(x, y): turtle.fillcolor("red") # turtle. onrelease(fun, btn=1, add=None) # fun – a function with two arguments which will be called with the coordinates of the clicked point on the canvas # num – number of the mouse-button, defaults to 1 (left mouse button) # add – True or False – if True, a new binding will be added,otherwise it will replace a former binding # Bind fun to mouse-button-release events on this turtle. If fun is None, existing bindings are removed. def unglow(x, y): turtle.fillcolor("") turtle.fd(100) turtle.lt(90) turtle.fd(100) turtle.lt(90) turtle.fd(100) turtle.lt(90) turtle.fd(100) turtle.onclick(glow) turtle.onrelease(unglow)
#NEW FUNCTION #1 turtle.dot(100, "lightblue") #creates a lightblue dot(size in pixels, color) turtle.forward(100) #NEW FUNCTION #2 #fills turtle color w/ violet and black border turtle.fillcolor("violet") #turtle does function without leaving a trace(invisible) def fun(): turtle.penup() turtle.goto(100,100) turtle.pendown() turtle.dot(100, "lightgreen") #creates a lightgreen dot at the point (50, 50) #NEW EVENT #1 turtle.onrelease(fun()) #when the user drags the turtle, it creates a drawing #if the penup function is used, the user can drag the turtle anywhere leaving an invisible trail turtle.penup() #NEW EVENT #2 turtle.ondrag(turtle.goto) #makes the turtle black and makes it write text with parameters turtle.color("black") turtle.write("Move the turtle inside the blue circle", move = True, align = "right", font=("Arial", 13, "normal")) #creates a function where the turtle writes text with parameters #makes the function run after 6000 milliseconds on a timer def function(): turtle.write("Good Job! ", move = True, align = "right", font=("Arial", 13, "normal"))
draw_circle(15, "yellow", "yellow") close_eyes() # mouth bob.width(15) jump(-70, 0) bob.setheading(-50) bob.color("black") bob.circle(100, 100) def wakeup(x, y): bob.asleep = False open_eyes() pass def sleep(x, y): bob.asleep = True close_eyes() pass screen.onclick(wakeup) turtle.onrelease(sleep) screen.listen() screen.mainloop()
def main(): # Bind a handler with the mouse-release event turtle.onrelease(displaySqaure) turtle.done()
import turtle wn = turtle.Screen() alex = turtle.Turtle() alex.shapesize(5,5,20) class MyTurtle(turtle.Turtle): def glow(self,x,y): self.fillcolor("red") def unglow(self,x,y): self.fillcolor("") turtle = MyTurtle() turtle.onclick(turtle.glow) turtle.onrelease(turtle.unglow) wn.mainloop()
def main(): #t.speed(20) #t.shapesize(1000,1000) t.up() t.goto(1000,0) #t.ht() #t.onkey(showTurtle,"a") #t.listen() t.onclick(getPos) t.onrelease(hideTurtle) t.mainloop() raw_input(">")
import turtle #t = turtle.Pen() #t.reset() #t.forward(100) #t.right(90) #t.forward(100) #t.right(90) #t.forward(100) #t.right(90) #t.forward(100) #t.hideturtle() turtle.Pen() turtle.forward(100) class MyTurtle(turtle): def glow(self,x,y): self.fillcolor("red") def unglow(self,x,y): self.fillcolor("") turtle = MyTurtle() turtle.onclick(turtle.glow) turtle.onrelease(turtle.unglow)