【问题标题】:how to get current width and height of turtle screen如何获取海龟屏幕的当前宽度和高度
【发布时间】:2021-05-14 14:01:45
【问题描述】:

我使用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()

【问题讨论】:

标签: python responsive-design turtle-graphics


【解决方案1】:

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

来自文档:

turtle.window_height()

返回海龟窗口的高度。

>>> screen.window_height()
480

【讨论】:

    猜你喜欢
    • 2011-09-25
    • 1970-01-01
    • 2010-11-25
    • 2011-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-07
    相关资源
    最近更新 更多