Is there a short way to get and set the window position in pygame?

Viewed 399

When I make my window smaller by dragging and dropping the top left corner to the direction of the bottom right corner, the window automatically resizes to the given minimum dimensions if its too small. The Problem is, the way its resizing. It expands to the bottom and to the right so if I make it too small it resizes itself and is not in the same position as before. How can I fix this ?

This is my videoresize event:

if event.type == pg.VIDEORESIZE:

        new_w, new_h = event.dict['size']   
        if new_w < 900:
            new_w = 900
        if new_h < 600:
            new_h = 600
        SCREEN = pg.display.set_mode((new_w, new_h), pg.RESIZABLE)
1 Answers

to set the window position on the screen before the window is initialised you would use os.environ['SDL_VIDEO_WINDOW_POS']

e.g.

x = 0
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)
Related