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)