I am using the pygame module on pycharm. Each time I run any program, the pygame window opened cannot be minimised or closed from the window. I have to stop the program from running or use the taskbar instead. It is starting to get annoying. Is there anyway to fix this?
This is the code I use to launch a program (if it’s of any use)
import pygame
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((800, 800))
pygame.display.set_caption('Test Window')
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pygame.display.update()
pygame.quit()
This is the resultant image when I run the program.
That’s the full screen. I did not crop anything out.
>Solution :
It looks like you’re running at 1920×1080, but PyGame somehow seems to think that’s not the case, since the window that opens is much larger than 800×800.
From the screenshot, we can tell you’re running on Windows. You may have some scaling accessibility settings enabled in the Windows, and Pygame uses that to scale up its full window as well.
Either compensate for the scaling if that’s the case (by creating a smaller window, or computing what size it should be), or don’t use the setting during development.
Have a look at:
import ctypes
ctypes.windll.user32.SetProcessDPIAware()
That may just resolve your issue, or you may need to look at passing some specific parameters to it to get the behaviour you want.
Edit:
After searching StackOverflow for that suggestion itself, it appears your question is really a duplicate of this: How to avoid scaling Pygame window when "make UI larger" is used in Windows? but I decided to leave my answer up, because I feel you asked the question very clearly, and that’s helpful.