Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
288 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 Reply

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...