3

So I have a pygame but the screen won't get bigger nor smaller. I can't make it larger. Any ideas on how to do it?

Hydro
  • 273
  • 1
  • 13

1 Answers1

3

You have to create a resizable display, by setting the pygame.RESIZABLE flag, when you call pygame.display.set_mode().

window = pygame.display.set_mode((width, height), pygame.RESIZABLE)

When the size of the window is changed, then the pygame.VIDEORESIZE event occurs. For instance:

import pygame

pygame.init()
window = pygame.display.set_mode((800, 600), pygame.RESIZABLE)

run = True
while run:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False
        elif event.type == pygame.VIDEORESIZE:
            window = pygame.display.set_mode((event.w, event.h), pygame.RESIZABLE)

    # [...]
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • at line 14 do I have to write (in your example) 500, 500 and what should i write at event.w and event.h. And then at the next line do I have to write ((500, 500)...) to? It douesn't work – Hydro May 18 '20 at 11:11
  • Hmmm... I don't get it. Or maybe I get it and something else doesn't work... ``` if event.type == pygame.QUIT: run = False pygame.quit() quit() elif event.type == pygame.VIDEORESIZE: (width = 800,height = 600) = event.w, event.h win = pygame.display.set_mode((800, 600), pygame.RESIZEABLE) ``` Is this false? – Hydro May 18 '20 at 11:18
  • thanks it worked. but the things I added before (buttons, ground,...) wont resize like the window. It'll stay the same. – Hydro May 18 '20 at 11:26
  • 2
    @RMR_MD Yes of course. Nothing happens automatically. You have to draw the objects dependent on the width and height of the screen. – Rabbid76 May 18 '20 at 11:35
  • And how do I do it. I can't figure it out – Hydro May 18 '20 at 11:50
  • 1
    @RMR_MD Now you would need `width` and `height` again (which you didn't like before). Anyway you can get the size of the window by [`window.get_size()`](https://www.pygame.org/docs/ref/surface.html#pygame.Surface.get_size) respectively the width and height separately by [`window.get_width()`](https://www.pygame.org/docs/ref/surface.html#pygame.Surface.get_width) and. [`window.get_height()`](https://www.pygame.org/docs/ref/surface.html#pygame.Surface.get_height). Recreate the buttons dependent on the current size of the window. – Rabbid76 May 18 '20 at 11:54
  • Wouldn't that mean that it would look strange while it's minimized? – Hydro May 18 '20 at 11:58
  • 1
    @RMR_MD No. You don't get the `pygame.VIDEORESIZE` event on minimize. The event occurs only on resize and maximize (fullscreen). Minimize just "hides" the window. – Rabbid76 May 18 '20 at 12:00
  • I am sorry if I bother you. I'm just a beginner and don't find the tutorials I need (mostly) and don't get answers else either. – Hydro May 18 '20 at 12:11
  • 1
    @RMR_MD I recommend the sites [PyGame - tutorials](https://www.pygame.org/wiki/tutorials) and [Pygame Front Page](https://www.pygame.org/docs/). In the light green area at the top of "Pygame Front Page" you can select different pygame modules and find the API documentation to different topics. The pygame API documentation is well structured and very detailed. – Rabbid76 May 18 '20 at 12:14
  • I can't find anything usefull. Can you tell me how to do it? – Hydro May 18 '20 at 12:37
  • I didn't find anything usefull sadly. Can you tell me how to do it? – Hydro May 18 '20 at 17:18
  • @RMR_MD What to do? Do you want to create a scalable button? The title of this question is *"How do I make my pygame window minimze and maximize?"*. I recommend to add a new question and to explain where you stuck. Please note the comment section is not intended for additional question. [Ask a public question](https://stackoverflow.com/questions/ask) a give all contributors the chance to give an answer and to receive reputation. – Rabbid76 May 18 '20 at 17:23