4

In a pygame application window, the minimize, resize and close buttons are present. Is there a way to disable the close(X) button?

Neeraj
  • 201
  • 3
  • 13
  • Do you have some code like `for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit(); sys.exit();`? – giodamelio Jul 08 '11 at 04:26
  • @giodamelio yes, there are such codes. I am just writing a desktop app that needs to keep running. I wanted to remove the X button so that the user does not inadvertently close the window.
    but mguica's suggestion works well. Do nothing.
    – Neeraj Jul 08 '11 at 04:34
  • 1
    It's nice when the answer to the question is essentially "do nothing" and it gets accepted :) – mgiuca Jul 08 '11 at 08:19
  • You could use win32gui and draw over the close button - https://stackoverflow.com/a/7585663/10474278 – Stemboy4002 Oct 22 '19 at 18:03

2 Answers2

6

I don't think there is, because some window managers don't give you the ability to remove the close button. But you can write an event handler such that the close button does whatever you want, including nothing.

Why do you want to prevent the user from closing? If it's just a matter that you would rather provide an in-game "quit" button that confirms and/or saves before quitting, you can perform the same task when the user hits the close button.

mgiuca
  • 20,958
  • 7
  • 54
  • 70
0

Just for the record, another option would be to pass the following argument to the set_mode() method call:

pygame.display.set_mode(..., flags = pygame.NOFRAME)

This however makes the whole frame go away, including the top strip to move the window around and the other buttons, such as minimize, so it's rather overkill for just getting rid of the X button.

LFB
  • 676
  • 2
  • 8
  • 20