当前位置: 首页>>代码示例>>Python>>正文


Python turtle.listen函数代码示例

本文整理汇总了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()
开发者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


注:本文中的turtle.listen函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。