如何在 PyGame 中更改 Surface(游戏窗口)相对于计算机屏幕的位置? [英] How can i change the position of a Surface(Game Window) with respect to computer Screen in PyGame?

查看:94
本文介绍了如何在 PyGame 中更改 Surface(游戏窗口)相对于计算机屏幕的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变游戏窗口相对于电脑屏幕的位置.但在文档中找不到任何内容.请帮我.

I want to change the position of Game window with respect to Computer Screen. But couldn't find anything in Documentation. Please Help me.

推荐答案

在 Windows 上,可以使用其句柄 (hwnd) 更改初始化窗口的位置.在 User32.dll 中有一个名为 MoveWindow,它接收一个窗口的句柄并改变它的位置.您可以使用 python 的标准 ctypes 模块调用它.

On windows, it is possible to change the position of an initialized window using its handle (hwnd). In User32.dll there is a function called MoveWindow, that recieves a window's handle and changes its position. You can call it using python's standard ctypes module.

from ctypes import windll

def moveWin(x, y):
    # the handle to the window
    hwnd = pygame.display.get_wm_info()['window']

    # user32.MoveWindow also recieves a new size for the window
    w, h = pygame.display.get_surface().get_size()

    windll.user32.MoveWindow(hwnd, x, y, w, h, False)

这篇关于如何在 PyGame 中更改 Surface(游戏窗口)相对于计算机屏幕的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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