本文整理汇总了Python中turtle.listen函数的典型用法代码示例。如果您正苦于以下问题:Python listen函数的具体用法?Python listen怎么用?Python listen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了listen函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: top_layer
def top_layer():
turtle.clearscreen()
screen_setup()
stations()
sp = turtle.Turtle()
sp.color('white')
sp.penup()
global top_pos
sp.setpos(top_pos)
sp.showturtle()
sp.speed(1)
def sta1():
turn_and_go(sp, 'sta1')
def sta2():
turn_and_go(sp, 'sta2')
def sta3():
turn_and_go(sp, 'sta3')
def zoom1():
global top_pos
top_pos = sp.pos()
global middle_sta1_pos
middle_sta1_pos = 250,-150
if sp.pos() == (200,75):
middle_layer_sta1()
else:
zoom()
turtle.onkey(sta1, 'a')
turtle.onkey(sta2, 'b')
turtle.onkey(sta3, 'c')
turtle.onkey(zoom1, '=')
turtle.listen()
示例2: zoom
def zoom():
time.sleep(0.5)
turtle.clearscreen()
screen_setup()
sp2 = turtle.Turtle()
sp2.color('white')
sp2.penup()
sp2.speed(0)
sp2.setpos(250, -150)
sp2.seth(90)
sp2.showturtle()
speed = (10)
b = 2
def turnleft():
sp2.left(30)
def turnright():
sp2.right(30)
def forward():
sp2.forward(speed)
def backward():
sp2.backward(speed)
turtle.onkey(forward, 'Up')
turtle.onkey(turnleft, 'Left')
turtle.onkey(turnright, 'Right')
turtle.onkey(backward, 'Down')
turtle.onkey(top_layer, '-')
turtle.listen()
示例3: play
def play(self):
cannon = LaserCannon()
turtle.ontimer(self.add_alien,2000)
turtle.listen()
# Start the event loop.
turtle.mainloop()
示例4: docking_layer
def docking_layer():
turtle.clearscreen()
screen_setup()
docking_port1()
sp3 = turtle.Turtle()
sp3.color('white')
sp3.penup()
sp3.speed(0)
sp3.setpos(300, 0)
sp3.seth(180)
sp3.showturtle()
speed = (10)
def turnleft():
sp3.left(30)
def turnright():
sp3.right(30)
def forward():
sp3.forward(speed)
def backward():
sp3.backward(speed)
turtle.onkey(forward, 'Up')
turtle.onkey(turnleft, 'Left')
turtle.onkey(turnright, 'Right')
turtle.onkey(backward, 'Down')
turtle.onkey(middle_layer_sta1, '-')
turtle.listen()
示例5: top_layer
def top_layer():
turtle.clearscreen()
screen_setup()
stations()
sp = turtle.Turtle()
sp.color('white')
sp.penup()
sp.setpos(200, 75)
sp.showturtle()
sp.speed(1)
def sta1():
sp.goto(200, 75)
def sta2():
sp.goto(-300, 45)
def sta3():
sp.goto(-100,-200)
def zoom1():
if sp.pos() == (200,75):
middle_layer_sta1()
else:
zoom()
turtle.onkey(sta1, 'a')
turtle.onkey(sta2, 'b')
turtle.onkey(sta3, 'c')
turtle.onkey(zoom1, '=')
turtle.listen()
示例6: middle_layer_sta1
def middle_layer_sta1():
time.sleep(0.5)
turtle.clearscreen()
screen_setup()
station_1()
sp2 = turtle.Turtle()
sp2.color('white')
sp2.penup()
sp2.speed(0)
sp2.setpos(250, -150)
sp2.seth(90)
sp2.showturtle()
speed = (10)
b = 2
def turnleft():
sp2.left(30)
def turnright():
sp2.right(30)
def forward():
sp2.forward(speed)
def backward():
sp2.backward(speed)
def zoom1():
if sp2.xcor() > -162 and sp2.xcor() < -98 and sp2.ycor() > -112 and sp2.ycor() < -64:
docking_layer()
turtle.onkey(forward, 'Up')
turtle.onkey(turnleft, 'Left')
turtle.onkey(turnright, 'Right')
turtle.onkey(backward, 'Down')
turtle.onkey(top_layer, '-')
turtle.onkey(zoom1,'=')
turtle.listen()
示例7: lab11
def lab11():
Line()
Rectangle()
Circle()
addkeys()
addmouse()
turtle.listen()
turtle.mainloop()
示例8: on_right
def on_right():
val = t.textinput('Right', "How much: ")
if val:
try:
val = int(val)
t.right(val)
except ValueError:
messagebox.showinfo('Error', 'Wrong value')
t.listen()
示例9: on_forward
def on_forward():
val = t.textinput('Forward', "How much: ")
if val:
try:
val = int(val)
t.forward(val)
except ValueError:
messagebox.showinfo('Error', 'Wrong value')
t.listen()
示例10: lab11
def lab11():
ring()
addkeys()
addmouse()
turtle.listen()
turtle.mainloop()
schoolLife()
speech()
示例11: main
def main():
# use sys.argv if needed
print('generating spirograph...')
# create parser
descStr = """This program draws spirographs using the Turtle module.
When run with no arguments, this program draws random spirographs.
Terminology:
R: radius of outer circle.
r: radius of inner circle.
l: ratio of hole distance to r.
"""
parser = argparse.ArgumentParser(description=descStr)
# add expected arguments
parser.add_argument('--sparams', nargs=3, dest='sparams', required=False,
help="The three arguments in sparams: R, r, l.")
# parse args
args = parser.parse_args()
# set to 80% screen width
turtle.setup(width=0.8)
# set cursor shape
turtle.shape('turtle')
# set title
turtle.title("Spirographs!")
# add key handler for saving images
turtle.onkey(saveDrawing, "s")
# start listening
turtle.listen()
# hide main turtle cursor
turtle.hideturtle()
# checks args and draw
if args.sparams:
params = [float(x) for x in args.sparams]
# draw spirograph with given parameters
# black by default
col = (0.0, 0.0, 0.0)
spiro = Spiro(0, 0, col, *params)
spiro.draw()
else:
# create animator object
spiroAnim = SpiroAnimator(4)
# add key handler to toggle turtle cursor
turtle.onkey(spiroAnim.toggleTurtles, "t")
# add key handler to restart animation
turtle.onkey(spiroAnim.restart, "space")
# start turtle main loop
turtle.mainloop()
示例12: set_keyboard_handler
def set_keyboard_handler(fn):
'''
Sets callback function to invoke when a key is pressed. The
function is passed the name of the key pressed as a string.
Only one keyboard handler may be registered at a time.
'''
_e.kbdfn = fn
# XXX why can't the turtle module just send the [email protected]&^#%$ keysym?
canvas = turtle.getcanvas()
canvas.bind('<KeyPress>', _E._keypress_cb)
turtle.listen()
示例13: tegn_romskip
def tegn_romskip():
turtle.penup()
turtle.shapesize(4)
turtle.setpos(200, 400)
turtle.setheading(90)
turtle.color('blue')
turtle.onkey(snu_hoyre, 'Right')
turtle.onkey(snu_venstre, 'Left')
turtle.onkey(bruk_motor, 'Up')
turtle.listen()
示例14: middle_layer_sta1
def middle_layer_sta1():
time.sleep(0.5)
turtle.clearscreen()
screen_setup()
station_1()
sp2 = turtle.Turtle()
sp2.color('white')
sp2.penup()
sp2.speed(0)
global middle_sta1_pos
sp2.setpos(middle_sta1_pos)
sp2.seth(90)
sp2.showturtle()
speed = (10)
b = 2
def turnleft():
sp2.left(30)
def turnright():
sp2.right(30)
def forward():
sp2.forward(speed)
def backward():
sp2.backward(speed)
def zoom1():
global middle_sta1_pos
middle_sta1_pos = sp2.pos()
if sp2.xcor() > -162 and sp2.xcor() < -98 and sp2.ycor() > -112 and sp2.ycor() < -64:
docking_layer()
turtle.onkey(forward, 'Up')
turtle.onkey(turnleft, 'Left')
turtle.onkey(turnright, 'Right')
turtle.onkey(backward, 'Down')
turtle.onkey(top_layer, '-')
turtle.onkey(zoom1,'=')
turtle.listen()
for i in range(1000):
x = random.randrange(-250, 450)
h = random.randrange(220, 340)
ship = turtle.Turtle()
ship.hideturtle()
ship.color('gray')
ship.penup()
ship.speed(0)
ship.setpos(x, 260)
ship.showturtle()
ship.speed(1)
ship.seth(h)
ship.forward(1000)
if sp2.xcor() > -162 and sp2.xcor() < -98 and sp2.ycor() > -112 and sp2.ycor() < -64:
break
示例15: set_relative_keyboard_bindings
def set_relative_keyboard_bindings(self):
"""Maps relative controls to player movement."""
turtle.listen()
# Set P1 keyboard bindings
turtle.onkeypress(self.P1.turn_left, 'a')
turtle.onkeypress(self.P1.turn_right, 'd')
turtle.onkeypress(self.P1.accelerate, 'w')
turtle.onkeypress(self.P1.decelerate, 's')
# Set P2 keyboard bindings
turtle.onkeypress(self.P2.turn_left, 'Left')
turtle.onkeypress(self.P2.turn_right, 'Right')
turtle.onkeypress(self.P2.accelerate, 'Up')
turtle.onkeypress(self.P2.decelerate, 'Down')