• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python turtle.onkey函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中turtle.onkey函数的典型用法代码示例。如果您正苦于以下问题:Python onkey函数的具体用法?Python onkey怎么用?Python onkey使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了onkey函数的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: 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


示例3: 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


示例4: __init__

    def __init__(self):
        super(LaserCannon, self).__init__()

        # Register events.  Note the function we register for 'q' is
        # a turtle function.
        turtle.onscreenclick(self.aim,1)
        turtle.onkey(self.shoot,"s")
        turtle.onkey(seeYaLater,'q')
开发者ID:eclass2790,项目名称:Alien_Invaders,代码行数:8,代码来源:Alien+Invader.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: 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


示例7: 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


示例8: 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


示例9: 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


示例10: 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


示例11: main

def main():
    descStr = "This draws spirographs with turtle graphics, if no arguments are given, random spirographs will be drawn."
    parser = argparse.ArgumentParser(description=descStr)
    #add expected args
    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 width of window to 80% of screen width
    turtle.setup(width=0.8)
    #set cursor shape to turtle
    turtle.shape('turtle')
    #set title to Spirographs!
    turtle.title("Spirographs!")
    #add keyhandler to save drawings
    turtle.onkey(saveDrawing, 's')
    #start listening
    turtle.listen()

    #hide main turtle cursor
    turtle.hideturtle()


    #check for any arguments sent to --sparams and draw spirograph
    if args.sparams:
        params = [float(x) for x in args.sparams]
        #draw spiro with given params
        col = (0.0, 0.0, 0.0)
        spiro = Spiro(0, 0, col, *params)
        spiro.draw()
    else:
        #create animator objects
        span = SpiroAnimator(6)
        #add key handler to toggle cursor
        turtle.onkey(span.toggleTurtles, "t")
        #add keyhandler to restart
        turtle.onkey(span.restart, "space")

    #start main loop
    turtle.mainloop()
开发者ID:georgevine,项目名称:Python_Playground,代码行数:42,代码来源:Spiro.py


示例12: up

import turtle

turtle.penup()
turtle.ht()

def up():
    print("You pressed Up!")

def down():
    print("You pressed Down!")

def left():
    print("You pressed Left!")

def right():
    print("You pressed Right!")
    
turtle.onkey(up, 'Up')
turtle.onkey(down, 'Down')
turtle.onkey(left, 'Left')
turtle.onkey(right, 'Right')

def repeat():
    turtle.ontimer(repeat, 500)

turtle.listen() # Remember to put this after your listeners!
开发者ID:mysticuno,项目名称:MEETY12015MiniProject,代码行数:26,代码来源:listeners_example.py


示例13: stamp

# functions to play with
def stamp():
  t1.stamp()
  t2.stamp()
def dot():
  t1.dot()
  t2.dot()
def testfun():
  x = t2.pen()
  t2.stamp()
  t2.pendown()
  t2.circle(100)
  t2.pen(x)

# global key event for turtle window
turtle.onkey(dot, "o")
turtle.onkey(stamp, "space")
w.onkey(testfun, "t")
w.onkey(w.bye, "x")

# extra key events for oturtles on window
t2._screen.onkey(t2.testfun,"h")

h.show(turtle._CFG)
print "use turtlekeys to move, v b m o space h t for Actions and x for close the Window"

# bind a callback on time
oldColor = None
def gruen(e):
  global oldColor
  print e
开发者ID:itbsStefan,项目名称:ots_network_turtle,代码行数:31,代码来源:main.py


示例14: colide

def colide(t1,t2):
        d = math.sqrt(math.pow(ugv1.xcor()-goal.xcor(),2) + math.pow(ugv1.ycor()-goal.ycor(),2))
        if d < 20:
                return True
        else:
                return False

def obstacle(t1,t2):
        d = math.sqrt(math.pow(ugv1.xcor()-green.xcor(),2) + math.pow(ugv1.ycor()-green.ycor(),2))
        if d < 30:
                ugv1.rt(30)
        
#Modo escucha de teclado
turtle.listen()
turtle.onkey(turnleft, "Left")
turtle.onkey(turnright, "Right")
turtle.onkey(speedup, "Up")
turtle.onkey(speeddown, "Down")
turtle.onkey(restart, "r")

#Inicio de movimiento
while speed>0:
        obstacle(ugv1,green)
        ugv1.forward(speed)
        
        #Mantener UGV dentro del ambiente
        if ugv1.xcor() > 300 or ugv1.xcor() < -300:
                ugv1.rt(180)

        if ugv1.ycor() > 300 or ugv1.ycor() < -300:
开发者ID:Roinflames,项目名称:desarrolloVoronoiPy,代码行数:30,代码来源:main+(copia).py


示例15: docking

def docking():
    cr = turtle.Turtle()
    cr.hideturtle()
    cr.color('gray')
    cr.speed(0)
    cr.penup()
    cr.setpos(0,250)
    cr.seth(270)
    cr.pendown()
    cr.forward(500)
    cr.penup()
    cr.setpos(450,0)
    cr.seth(180)
    cr.pendown()
    cr.forward(900)
    
    def left():
      global cenx  
      global x
      x = x-10
      cenx = cenx-10
    def right():
      global cenx
      global x
      x = x+10
      cenx = cenx+10
    def up():
      global y
      global ceny
      y = y+10
      ceny = ceny+10
    def down():
      global y
      global ceny
      y = y-10
      ceny = ceny-10
    for i in range(100):
        global r
        global x
        global cens
        ma.setx(cenx)
        ma.sety(ceny)
        al.setx(x)
        al.sety(y)
        al.pendown()
        al.seth(90)
        al.clear()
        ma.clear()
        al.circle(r)
        ma.dot(cens, 'white')
        al.penup()
        r = r+1
        x = x+1
        if cens <= 10:
            cens+0.5
        turtle.onkey(left, 'Left')
        turtle.onkey(right, 'Right')
        turtle.onkey(up, 'Up')
        turtle.onkey(down, 'Down')
        turtle.listen()
        turtle.delay(50)
开发者ID:BrynSussex,项目名称:bryn-s-game-,代码行数:61,代码来源:docking+test+1.py


示例16: main

def main():
    display_help_window()

    scr = turtle.Screen()
    turtle.mode('standard')
    xsize, ysize = scr.screensize()
    turtle.setworldcoordinates(0, 0, xsize, ysize)

    turtle.hideturtle()
    turtle.speed('fastest')
    turtle.tracer(0, 0)
    turtle.penup()

    board = LifeBoard(xsize // CELL_SIZE, 1 + ysize // CELL_SIZE)

    # Set up mouse bindings
    def toggle(x, y):
        cell_x = x // CELL_SIZE
        cell_y = y // CELL_SIZE
        if board.is_legal(cell_x, cell_y):
            board.toggle(cell_x, cell_y)
            board.display()

    turtle.onscreenclick(turtle.listen)
    turtle.onscreenclick(toggle)

    board.makeRandom()
    board.display()

    # Set up key bindings
    def erase():
        board.erase()
        board.display()
    turtle.onkey(erase, 'e')

    def makeRandom():
        board.makeRandom()
        board.display()
    turtle.onkey(makeRandom, 'r')

    turtle.onkey(sys.exit, 'q')

    # Set up keys for performing generation steps, either one-at-a-time or not.
    continuous = False
    def step_once():
        nonlocal continuous
        continuous = False
        perform_step()

    def step_continuous():
        nonlocal continuous
        continuous = True
        perform_step()

    def perform_step():
        board.step()
        board.display()
        # In continuous mode, we set a timer to display another generation
        # after 25 millisenconds.
        if continuous:
            turtle.ontimer(perform_step, 25)

    turtle.onkey(step_once, 's')
    turtle.onkey(step_continuous, 'c')

    # Enter the Tk main loop
    turtle.listen()
    turtle.mainloop()
开发者ID:MattRijk,项目名称:algorithms,代码行数:68,代码来源:conway_game_of_life.py


示例17: move

def move():
    din = raw_input("Go left or right? ")
    direction = din.strip().lower()
    print "okay then", direction
    if direction == "left":
        turtle.left(90)
        turtle.forward(length)
        dashforward(100)
    if direction == "right":
        turtle.right(90)
        turtle.forward(length)
        hexagon()


turtle.onkey(turtleUp, "Up")  #  90
turtle.onkey(turtleDown, "Down")  # 270
turtle.onkey(turtleLeft, "Left")  # 180
turtle.onkey(turtleRight, "Right")  #  0
turtle.onkey(togglePen, "p")
turtle.onkey(dot, "d")
turtle.onkey(lengthPlus, "bracketright")
turtle.onkey(lengthMinus, "slash")
turtle.onkey(move, "m")


def callback(e):
    print e.keysym, repr(e.char)


w = turtle.Screen()
开发者ID:haikoschol,项目名称:ots_network_turtle,代码行数:30,代码来源:otsTurtle.py


示例18: 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


示例19: place5

def place5():
    global cur_player
    if (cur_player == 1):
        play1(5)
    elif (cur_player == 2):
        play2(5)

def place6():
    global cur_player
    if (cur_player == 1):
        play1(6)
    elif (cur_player == 2):
        play2(6)

#key listeners
turtle.onkey(place0, '1')
turtle.onkey(place1, '2')
turtle.onkey(place2, '3')
turtle.onkey(place3, '4')
turtle.onkey(place4, '5')
turtle.onkey(place5, '6')
turtle.onkey(place6, '7')

        
#drawing the board        
draw_board(START_X , START_Y)

turtle.listen()
turtle.mainloop()
开发者ID:mprat,项目名称:meet-y1-2014-connect4,代码行数:29,代码来源:connect4withlisteners.py


示例20: k1

player2 = turtle.Turtle()

player2.color('blue')
player2.shape('turtle')

player2.penup()
player2.goto(-160, 0)
player2.pendown()

# button functions
def k1():
    player1.forward(10)
    if player1.xcor() > 100:
        print("player 1 wins")
        window.bye()

def k2():
    player2.forward(10)
    if player2.xcor() > 100:
        print("player 2 wins")
        window.bye()
def k3():
    window.bye()

#########     
turtle.listen()
turtle.onkey(k1, "Left")
turtle.onkey(k2, "Right")
turtle.onkey(k3, 'q')
    
开发者ID:learnICT,项目名称:RPi-club,代码行数:29,代码来源:TurtleRacers.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python turtle.onscreenclick函数代码示例发布时间:2022-05-27
下一篇:
Python turtle.mainloop函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap