如何改变乌龟的大小? [英] How to change size of turtle?
本文介绍了如何改变乌龟的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每次我按键盘上的 x
时,我都试图将窗口中海龟的大小加倍.我尝试使用 .turtlesize(2,2,2)
,但这是不对的.每次按下键时我都需要加倍,所以如果海龟大小是 (1,1,1)
,它将变成 (2,2,2)
然后 (4,4,4)
等等,每次我按 x
.
I am trying to double the size of the turtle in the window every time I press x
on my keyboard. I tried using .turtlesize(2,2,2)
, but that's not right. I need to double every time the key is pressed so if the turtle size is (1,1,1)
, it will become (2,2,2)
then (4,4,4)
and so on each time I press x
.
这是我目前所拥有的:
import turtle
turtle.setup(500,500)
wn = turtle.Screen()
wn.title("Commands")
wn.bgcolor("black")
tess = turtle.Turtle()
tess.shape("triangle")
tess.color("red")
tess.left(90)
def increaseSize():
size = tess.turtlesize()
increase = tuple([2 * num for num in size])
tess.turtlesize(increase) #this is where the error occurs
wn.onkey(increaseSize, "x")
wn.listen()
推荐答案
更改这一行:
tess.turtlesize(increase)
改为:
tess.turtlesize(*increase)
turtlesize()
需要三个单独的值,但您传递的是三个值中的一个元组,因此我们需要将该元组分布在参数列表中.
turtlesize()
wants three separate values but you were passing one tuple of three values so we need to spread that tuple across the argument list.
这篇关于如何改变乌龟的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文