Python、海龟图形、键绑定 [英] Python, Turtle Graphics, Key bindings

查看:68
本文介绍了Python、海龟图形、键绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到一种方法,当我按住某个键时,玩家会不断移动,或者只是让玩家不断向前移动,只使用海龟图形,(我也安装了 pygame)

I'm trying to figure out a way to make it to when I hold down a key the player will constantly move, or just have the player move forward constantly with just turtle graphics, (I do have pygame installed also)

import turtle
from turtle import *

#Setup Screen
wn = turtle.Screen()
wn.setup(700,700)
wn.title("white")
wn.bgcolor("black")

#Create Player
player = turtle.Turtle()
player.penup()
player.shape("triangle")
player.color("white")

def forward():
    player.forward(20)

def lef():
    player.left(90)

def forward():
    player.right(90)

onkey(forward,"Up")
onkey(left,"Left")
onkey(right,"Right")

listen()

推荐答案

您可以通过在

wn.onkey(forward, 'Up')
wn.onkey(left, 'Left')
wn.onkey(right, 'Right')

wn.listen()
wn.mainloop()

我希望这会有所帮助!

这篇关于Python、海龟图形、键绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆