I want to change the position of Game window with respect to Computer Screen. But couldn't find anything in Documentation. Please Help me.
Asked
Active
Viewed 929 times
0
-
[pygame-display-position](http://stackoverflow.com/questions/4135928/pygame-display-position) – furas Jul 14 '14 at 10:47
2 Answers
2
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)

kmaork
- 5,722
- 2
- 23
- 40
1
You can set the position that the pygame display initializes with environment variables that can be accessed with os.environ. An example from http://www.pygame.org/wiki/SettingWindowPosition?parent=CookBook:
x = 100
y = 0
import os
os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (x,y)
import pygame
pygame.init()
screen = pygame.display.set_mode((100,100))
# wait for a while to show the window.
import time
time.sleep(2)
I do not think it's possible to change the position of an already initialized display, but you could quit the current display, set the environment variable, and reinitialize it.

KSab
- 502
- 2
- 12