[Edu-sig] onClick(goto)
Gregor Lingl
glingl at aon.at
Sat Jun 24 16:24:50 CEST 2006
Hi all of you!
In a previous post I used
>>> onClick(goto).
No reaction. Hmmm... (perhaps nobody clicked)
For those of you, who didn't have the opportunity to look
into the xturtle.py package, here is a typical untypical
example for the use of xturtle, 25 lines of code,
say painter.py:
""" A tiny paint program.
After startup use mouse-buttons:
left - to move pen
right - to switch penstate from up to down and
vice versa. switching to up begins filling,
to down ends (and performs) filling
middle - to switch color (you may use different colors
for drawing lines and filling)
draw and have fun!
"""
from xturtle import *
def switchupdown(x, y):
if pen()["pendown"]:
end_fill()
up()
else:
down()
begin_fill()
def changecolor(x, y):
colors.append(colors.pop(0))
color(colors[0])
shape("circle")
resizemode("user")
turtlesize(0.5)
width(3)
colors=["red", "green", "blue", "yellow"]
color(colors[0])
up()
onClick(goto,1)
onClick(changecolor,2)
onClick(switchupdown,3)
mainloop() ## comment out if used from within IDLE with -n switch
### end of program
I think, this example shows, that fairly simple use
of fairly advanced concepts can lead to a fairly
funny result.
Try it out.
Have a nice weekend.
Gregor
More information about the Edu-sig
mailing list