Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why can't I find the close button on my pygame window?

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.
enter image description here That’s the full screen. I did not crop anything out.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading