2

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)
derpascal
  • 172
  • 1
  • 10
  • What have you tried so far? How do you handle `pygame.VIDEORESIZE` events? Please edit your question to include a [mcve] to make it possible to assist you. I have a minimal resize answer [here](https://stackoverflow.com/a/64236319/7675174), perhaps that could help. – import random Oct 07 '20 at 22:36
  • I edited my post. Do you know how I can include something so that the window stays where it was IF the user made it too small ? – derpascal Oct 07 '20 at 22:46
  • Is it okay to use a fixed window position as described by @reece? If not, it will probably be operating system specific, [this answer](https://stackoverflow.com/a/37001771) will get you started for Windows. Or you could try pygame2 which [supports moving the window](https://stackoverflow.com/a/62182113). – import random Oct 08 '20 at 01:04

1 Answers1

1

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)