如何获得我的 pygame 窗口的大小(宽 x 高) [英] How do I get the size (width x height) of my pygame window

查看:191
本文介绍了如何获得我的 pygame 窗口的大小(宽 x 高)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用

pygame.display.set_mode((width, height), 
                        pygame.OPENGL | pygame.DOUBLEBUF | pygame.RESIZABLE)

稍后在应用程序中,我希望能够询问该窗口的宽度和高度,以便我可以决定如何处理鼠标位置.

Later on in the app I want to be able to ask that window its width and height so I can decide how to process the mouse position.

如何在程序的其他地方访问该 pygame 窗口的尺寸?(事件处理循环)

How do I access the dimensions of that pygame window elsewhere in the program? (event processing loop)

推荐答案

你想要得到表面,然后从表面对象中得到大小.

You want to get the surface, then get the size from the surface object.

使用元组解包:

w, h = pygame.display.get_surface().get_size()

这篇关于如何获得我的 pygame 窗口的大小(宽 x 高)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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