Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
272 views
in Technique[技术] by (71.8m points)

python - How can i change the position of a Surface(Game Window) with respect to computer Screen in PyGame?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...