本文整理汇总了Python中turtle.listen函数的典型用法代码示例。如果您正苦于以下问题:Python listen函数的具体用法?Python listen怎么用?Python listen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了listen函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
开发者ID:BrynSussex,项目名称:bryn-s-game-,代码行数:34,代码来源:navigation.py
示例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()
开发者ID:johnkershaw,项目名称:bryn_game,代码行数:29,代码来源:docking.py
示例3: play
def play(self):
cannon = LaserCannon()
turtle.ontimer(self.add_alien,2000)
turtle.listen()
# Start the event loop.
turtle.mainloop()
开发者ID:eclass2790,项目名称:Alien_Invaders,代码行数:7,代码来源:Alien+Invader.py
示例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()
开发者ID:johnkershaw,项目名称:bryn_game,代码行数:27,代码来源:docking.py
示例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()
开发者ID:johnkershaw,项目名称:bryn_game,代码行数:26,代码来源:docking.py
示例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()
开发者ID:johnkershaw,项目名称:bryn_game,代码行数:34,代码来源:docking.py
示例7: lab11
def lab11():
Line()
Rectangle()
Circle()
addkeys()
addmouse()
turtle.listen()
turtle.mainloop()
开发者ID:jongin08,项目名称:p1_200911208,代码行数:8,代码来源:wk11_turtlegame(2).py
示例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()
开发者ID:golubaca,项目名称:python-examples,代码行数:9,代码来源:main.py
示例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()
开发者ID:golubaca,项目名称:python-examples,代码行数:9,代码来源:main.py
示例10: lab11
def lab11():
ring()
addkeys()
addmouse()
turtle.listen()
turtle.mainloop()
schoolLife()
speech()
开发者ID:jongin08,项目名称:p1_200911208,代码行数:9,代码来源:wk11_main.py
示例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()
开发者ID:diopib,项目名称:pp,代码行数:57,代码来源:spiro.py
示例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()
开发者ID:sbihel,项目名称:retrogames,代码行数:11,代码来源:engine.py
示例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()
开发者ID:gahjelle,项目名称:gahjelle.github.io,代码行数:11,代码来源:rosetta_og_philae.py
示例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
开发者ID:BrynSussex,项目名称:bryn-s-game-,代码行数:52,代码来源:night+phantom+interface+-Mk.II.py
示例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')
开发者ID:ricebullet,项目名称:tron,代码行数:14,代码来源:game.py
示例16: set_listeners
def set_listeners(self):
turtle.onscreenclick(self.clickcb, 1)
# In OSX, ctrl-click doesn't give a button-3 click. Instead,
# trackpad users have to enable secondary click in system
# preferences. Then, right-clicking on trackpad generates a
# button-2 click. I don't know what one-button mouse users can
# do?
turtle.onscreenclick(self.rightclickcb, 2)
# On Linux, right-click generates a button-3 click.
turtle.onscreenclick(self.rightclickcb, 3)
turtle.onkey(self.spacecb, "space")
turtle.onkey(self.savecb, "s")
turtle.onkey(self.redisplaycb, "r")
turtle.listen()
开发者ID:ElliotGluck,项目名称:ponyge,代码行数:14,代码来源:gui.py
示例17: save_graph
def save_graph():
import ImageGrab #windows only, for now
from tkFileDialog import asksaveasfilename as save
canvas = turtle.getscreen().getcanvas()
turtle.update()
turtle.listen()
canvas.update()
x0 = canvas.winfo_rootx()
y0 = canvas.winfo_rooty()
x1 = x0 + canvas.winfo_width()
y1 = y0 + canvas.winfo_height()
turtle.listen()
image = ImageGrab.grab((x0,y0, x1,y1))
filename = save(defaultextension='.png')
image.save(filename, "PNG")
showinfo("File Saved",("File successfully saved as %s" %filename))
开发者ID:hchasestevens,项目名称:chasestevens.com,代码行数:16,代码来源:turtlegraph.py
示例18: start
def start(x,y):
turtle.onscreenclick(None)
level_1()
tfood = turtle.Turtle()
tfood.hideturtle()
tfood.pu()
tfood.speed(0)
tfood.shape("square")
tfood.color("red")
tscore = turtle.Turtle()
tscore.hideturtle()
tscore.pu()
tscore.speed(0)
tscore.goto(100,-250)
tscore.write("Score:" + str(a[0]), align="center",font=(10))
while x > -210 and x < 210 and y > -210 and y <210:
if fcoord[2] == 0:
food(tfood)
fcoord[2] = 1
turtle.onkey(u,"Up")
turtle.onkey(l,"Left")
turtle.onkey(r,"Right")
turtle.onkey(d,"Down")
turtle.listen()
move()
x = turtle.xcor()
y = turtle.ycor()
if x > fcoord[0]*20-5 and x < fcoord[0]*20+5 and y > fcoord[1]*20-5 and y < fcoord[1]*20+5:
fcoord[2] = 0
tfood.clear()
a[0] += 1
tscore.clear()
tscore.write("Score:" + str(a[0]), align="center",font=(10))
if len(pos) > 1:
for i in range(1,len(pos)):
if x < pos[i][0]+5 and x > pos[i][0]-5 and y < pos[i][1]+5 and y > pos[i][1]-5:
tscore.clear()
tfood.clear()
gameover()
tscore.clear()
tfood.clear()
gameover()
开发者ID:DCoelhoM,项目名称:Snake-Python,代码行数:47,代码来源:Snake_by_DCM.py
示例19: set_abs_keyboard_bindings
def set_abs_keyboard_bindings(self):
"""Maps absolute controls to player movement."""
turtle.listen()
# Set P1 keyboard bindings
if self.P1.heading() == 0: # East
turtle.onkeypress(self.P1.turn_left, 'w')
turtle.onkeypress(self.P1.turn_right, 's')
turtle.onkeypress(self.P1.accelerate, 'd')
turtle.onkeypress(self.P1.decelerate, 'a')
elif self.P1.heading() == 90: # North
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')
elif self.P1.heading() == 180: # West
turtle.onkeypress(self.P1.turn_left, 's')
turtle.onkeypress(self.P1.turn_right, 'w')
turtle.onkeypress(self.P1.accelerate, 'a')
turtle.onkeypress(self.P1.decelerate, 'd')
elif self.P1.heading() == 270: # South
turtle.onkeypress(self.P1.turn_left, 'd')
turtle.onkeypress(self.P1.turn_right, 'a')
turtle.onkeypress(self.P1.accelerate, 's')
turtle.onkeypress(self.P1.decelerate, 'w')
# Set P1 keyboard bindings
if self.P2.heading() == 0: # East
turtle.onkeypress(self.P2.turn_left, 'Up')
turtle.onkeypress(self.P2.turn_right, 'Down')
turtle.onkeypress(self.P2.accelerate, 'Right')
turtle.onkeypress(self.P2.decelerate, 'Left')
elif self.P2.heading() == 90: # North
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')
elif self.P2.heading() == 180: # West
turtle.onkeypress(self.P2.turn_left, 'Down')
turtle.onkeypress(self.P2.turn_right, 'Up')
turtle.onkeypress(self.P2.accelerate, 'Left')
turtle.onkeypress(self.P2.decelerate, 'Right')
elif self.P2.heading() == 270: # South
turtle.onkeypress(self.P2.turn_left, 'Right')
turtle.onkeypress(self.P2.turn_right, 'Left')
turtle.onkeypress(self.P2.accelerate, 'Down')
turtle.onkeypress(self.P2.decelerate, 'Up')
开发者ID:ricebullet,项目名称:tron,代码行数:45,代码来源:game.py
示例20: hold
def hold(self):
""" holds the screen open until the user clicks or types 'q' """
# have the turtle listen for events
turtle.listen()
# hide the turtle and update the screen
turtle.ht()
turtle.update()
# have the turtle listen for 'q'
turtle.onkey( turtle.bye, 'q' )
# have the turtle listen for a click
turtle.onscreenclick( lambda x,y: turtle.bye() )
# start the main loop until an event happens, then exit
turtle.mainloop()
exit()
开发者ID:akaralekas,项目名称:cs151-colby,代码行数:18,代码来源:turtle_interpreter.py
注:本文中的turtle.listen函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论