0

I want to be able to resize a pygame window while keeping a minimum width and height. The answers I've read (1 2 3 4) say to set_mode. The docs say that a set_mode isn't necessary in 2.x pygame because it's automatically resized, but I need to manually resize it to prevent the window from being made too small.

The expected behavior is for it to just refuse to become smaller (if you open a random IDE or text editor and try to squish it, and it will refuse to go smaller beyond a point). However, if I run this on linux, it flickers. It quickly closes the window and creates a new one that's slightly bigger/smaller.

Interestingly, when I tried this on windows, it works fine as intended. This might be because windows gives me the VIDEORESIZE event after I release the mouse, so I'm able to squish the window really small, and then let go of my mouse and have the window snap back to its original position.

Both are running pygame v2.1.2. What's causing the window to behave like this specifically on linux?

Minimal code

import pygame

MIN_WIDTH = 800
MIN_HEIGHT = 600

pygame.init()
pygame.display.set_caption('Resizable Window Test')
canvas = pygame.display.set_mode((800, 600), pygame.RESIZABLE)

while True:
    canvas.fill(0x444444)
    pygame.display.update()
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            exit()
        if event.type == pygame.VIDEORESIZE:
            # This line is needed to keep the minimum width/height, but results in the flickering.
            pass
            #canvas = pygame.display.set_mode((max(event.w, MIN_WIDTH), max(event.h, MIN_HEIGHT)), pygame.RESIZABLE)
Eric Jin
  • 3,836
  • 4
  • 19
  • 45
  • 1
    Probably this problem is not solvable. At least there is nothing in your code that you can do to solve this problem. As you found out, the problem is system dependent. You could possibly consider it a bug in Pygame and create an issue there (https://github.com/pygame/pygame/issues). The question *"What's causing the window to behave like this specifically on linux?"* is not appropriate for StackOverflow, because it can only be answered by someone who develops Pygame, but not by someone who develops in Pygame. – Rabbid76 Nov 26 '22 at 08:19

0 Answers0