如何获取海龟屏幕的当前宽度和高度

时间:2021-05-14 14:01:45

标签: python responsive-design turtle-graphics

我使用 screen.setup() 来设置屏幕,但是当用户调整屏幕大小时 我怎样才能获得更改,以便我可以使应用程序响应调整大小 我需要将该整数更改为 screen_width-20:

screen = Screen()
screen.setup(height=600,width=800)

这是我实现的版本

#collision with wall
    if ball.ycor() > 280 or ball.ycor() < -280:
        ball.bounce_y()

我要实现的是

#collision with wall
    if ball.ycor() >screen_height-20 or ball.ycor() < -(screen_height-20):
        ball.bounce_y()

1 个答案:

答案 0 :(得分:0)

您可以使用 turtle.window_height() 方法。

来自文档:

<块引用>

turtle.window_height()

返回海龟窗口的高度。

>>> screen.window_height()
480