The Wayback Machine - https://web.archive.org/web/20241010042905/https://www.geeksforgeeks.org/allowing-resizing-window-in-pygame/
Open In App

Allowing resizing window in PyGame

Last Updated : 24 Jan, 2021
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

In this article, we will learn How to allow resizing a PyGame Window. 

Game programming is very rewarding nowadays and it can also be used in advertising and as a teaching tool too. Game development includes mathematics, logic, physics, AI, and much more and it can be amazingly fun. In python, game programming is done in pygame and it is one of the best modules for doing so.

Installation:

This library can be installed using the below command:

pip install pygame 

Normal PyGame Window

Steps-by-step Approach:

  1. Import pygame.
  2. Set the title and add content.
  3. Run pygame.
  4. Quit pygame.

Below is the program based on the above approach:

Python3




# import package pygame
import pygame
  
# Form screen with 400x400 size
# with not resizable
screen = pygame.display.set_mode((400, 400))
  
# set title
pygame.display.set_caption('Not resizable')
  
# run window
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
  
# quit pygame after closing window
pygame.quit()


Output :

Resizable PyGame Window

Step-by-step Approach:

  1. Import pygame.
  2. Form a screen by using pygame.display.set_mode() method and allow resizing using pygame.RESIZABLE .
  3. Set the title and add content.
  4. Run pygame.
  5. Quit pygame.

Below is the program based on the above approach:

Python3




# import package pygame
import pygame
  
# Form screen with 400x400 size
# and with resizable
screen = pygame.display.set_mode((400, 400), 
                                 pygame.RESIZABLE)
  
# set title
pygame.display.set_caption('Resizable')
  
# run window
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
  
# quit pygame after closing window
pygame.quit()


Output :



Previous Article
Next Article

Similar Reads

PyQt5 – How to stop resizing of window | setFixedSize() method
In this article, we will see how to stop resizing of the main window. While making a window, we get options like going full screen and using cursor to change its size. By using setFixedSize() method we can prevent the resizing of the image. Syntax : self.setFixedSize(width, height) Argument : It takes two integer as argument i.e width and height. A
1 min read
PYGLET – Setting Size / Resizing of Window
In this article we will see how we can set the size of the window in PYGLET module in python. Pyglet is easy to use but powerful library for developing visually rich GUI applications like games, multimedia etc. A window is a "heavyweight" object occupying operating system resources. Windows may appear as floating regions or can be set to fill an en
2 min read
Dynamically Resize Buttons When Resizing a Window using Tkinter
Prerequisite: Python GUI – tkinter Button size is static, which means the size of a button cannot be changed once it is defined by the user. The problem here is while resizing the window size, it can affect the button size problem. So the solution here is, make a dynamic button, which means the button size will change as per window size. Let's unde
2 min read
Adding Collisions Using pygame.Rect.colliderect in Pygame
Prerequisite: Drawing shapes in Pygame, Introduction to pygame In this article, we are going to use pygame.Rect.colliderect for adding collision in a shape using Pygame in Python. We can easily add collisions in Pygame shapes using the colliderect( ). For this, we are going to draw two rectangles then we will check if the rectangles are colliding o
3 min read
PyQt5 QSpinBox - Allowing wrapping the value
In this article we will see how we can make the spin box to make wrapping the value. Wrapping will make the stepping up from maximum value change value to the lowest value, similarly stepping down from minimum value change value to the maximum value just like cycle. Note : Wrapping only make sense if you have minimum and maximum values are set. In
2 min read
Python | Display text to PyGame window
Pygame is a cross-platform set of Python modules designed for writing video games. It includes computer graphics and sound libraries designed to be used with the Python programming language. Now, it’s up to the imagination or necessity of the developer, what type of game he/she wants to develop using this toolkit.. Command to install pygame on wind
6 min read
Python | Drawing different shapes on PyGame window
Pygame is a cross-platform set of Python modules designed for writing video games. It includes computer graphics and sound libraries designed to be used with the Python programming language. Now, it’s up to the imagination or necessity of developer, what type of game he/she wants to develop using this toolkit. Command to install pygame : pip instal
3 min read
How to create an empty PyGame window?
Pygame window is a simple window like any other window, in which we display our game screen. It is the first task we do so that we can display our output onto something. Our main goal here is to create a window and keep it running unless the user wants to quit. To perform these tasks first we need to install pygame package and import some pre-defin
2 min read
How to get the size of PyGame Window?
In this article, we will learn How to get the size of a PyGame Window. Game programming is very rewarding nowadays and it can also be used in advertising and as a teaching tool too. Game development includes mathematics, logic, physics, AI, and much more and it can be amazingly fun. In python, game programming is done in pygame and it is one of the
2 min read
How to make a PyGame Window?
PyGame is a free and open-source cross-platform library for game development in Python. It was officially written by Pete Shinners to replace PySDL it is suitable for the creation of client-side applications and acts as standalone executables. In this article, we are going to see how to make Pygame window in Python. Command to install pygame on Win
2 min read
How to Change the Name of a Pygame window?
PyGame window is a simple window that displays our game on the window screen. By default, pygame uses "Pygame window" as its title and pygame icon as its logo for pygame window. We can use set_caption() function to change the name and set_icon() to set icon of our window. To change the name of pygame window: Syntax: pygame.display.set_caption('Titl
2 min read
How to make a fully transparent window with PyGame ?
Fully transparent windows with PyGame have their own advantage while building many games and apps via Python. Thus in order to achieve the functionality of the transparent window that allows the user to see behind a running screen. For example: Geek want to design an app, in which they can see the background screen of the other windows. Thus in ord
3 min read
Image Resizing in Matlab
Prerequisite : RGB image representation MATLAB stores most images as two-dimensional matrices, in which each element of the matrix corresponds to a single discrete pixel in the displayed image. Some images, such as truecolor images, represent images using a three-dimensional array. In truecolor images, the first plane in the third dimension represe
2 min read
PyQt5 QSpinBox - Resizing it according to value
In this article we will see how we can resize the spin box according to its value. We can set the dimension of the spin box with the help of setGeometry method although it takes position argument as well therefore resizing it is not appropriate. In order to do this we use resize method with the spin box object. Syntax : spin_box.resize(width, heigh
2 min read
Mahotas - Resizing Image
In this article we will see how we can resize the image in mahotas. Image interpolation occurs when you resize or distort your image from one pixel grid to another. Image resizing is necessary when you need to increase or decrease the total number of pixels, whereas remapping can occur when you are correcting for lens distortion or rotating an imag
2 min read
MoviePy – Resizing Video File
In this article, we will see how we can resize video file clips in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. Resizing video files means. Image/frame interpolation occurs when you resize or distort your frame of video from one-pixel grid to another. Video resizing is necessary
3 min read
Image resizing using Seam carving using OpenCV in Python
Seam carving is an effective image processing technique with the help of which an image can be resized without removing important elements from the image. The basic approach is to find all the continuous pixels with low energy from left to right or from top to bottom. After the region is selected, it is removed from the original image, leaving only
2 min read
Python OpenCV - Bicubic Interpolation for Resizing Image
Image resizing is a crucial concept that wishes to augment or reduce the number of pixels in a picture. Applications of image resizing can occur under a wider form of scenarios: transliteration of the image, correcting for lens distortion, changing perspective, and rotating a picture. The results of resizing greatly vary looking on the kind of inte
9 min read
Expanding the Canvas Without Resizing in Python Pillow
The Python Imaging Library (PIL) is a powerful tool for image processing in Python, offering a wide range of functionalities from basic image manipulations to complex operations. One of the useful features of PIL is the ability to expand the canvas of an image without resizing the original content. This article explores the concept of expanding the
4 min read
Image Resizing using OpenCV | Python
Image resizing refers to the scaling of images. Scaling comes in handy in many image processing as well as machine learning applications. It helps in reducing the number of pixels from an image and that has several advantages e.g. It can reduce the time of training of a neural network as the more the number of pixels in an image more is the number
4 min read
PyQtGraph – Getting Window Flags of Plot Window
In this article we will see how we can get window flags of the plot window in the PyQtGraph module. PyQtGraph is a graphics and user interface library for Python that provides functionality commonly required in designing and science applications. Its primary goals are to provide fast, interactive graphics for displaying data (plots, video, etc.) an
3 min read
PyQtGraph – Setting Window Flag to Plot Window
In this article we will see how we can set window flag to the plot window in the PyQtGraph module. PyQtGraph is a graphics and user interface library for Python that provides functionality commonly required in designing and science applications. Its primary goals are to provide fast, interactive graphics for displaying data (plots, video, etc.) and
3 min read
How to create a text input box with Pygame?
In this article, we will discuss how to create a text input box using PyGame. Installation Before initializing pygame library we need to install it. This library can be installed into the system by using pip tool that is provided by Python for its library installation. Pygame can be installed by writing these lines into the terminal. We can install
3 min read
How to add moving platforms in PyGame
Prerequisite: Drawing in Pygame In this article, we will learn how we can add moving platforms to our game using PyGame in Python. Creating a Platform We can easily create any type of platform in pygame using the draw( ) method. For this, we will create react with specific width and height using the draw.rect() function. Syntax: pygame.draw.rect(su
5 min read
How to get keyboard input in PyGame ?
While using pygame module of Python, we sometimes need to use the keyboard input for various operations such as moving a character in a certain direction. To achieve this, we have to see all the events happening. Pygame keeps track of events that occur, which we can see with the events.get() function. In this article, we are going to discuss how we
3 min read
Pygame - Surface
When using Pygame, surfaces are generally used to represent the appearance of the object and its position on the screen. All the objects, text, images that we create in Pygame are created using surfaces. Creating a surface Creating surfaces in pygame is quite easy. We just have to pass the height and the width with a tuple to pygame.Surface() metho
6 min read
Python | Display images with PyGame
Pygame is a cross-platform set of Python modules designed for writing video games. It includes computer graphics and sound libraries designed to be used with the Python programming language. Now, it’s up to the imagination or necessity of the developer, what type of game he/she wants to develop using this toolkit. Command to install pygame : pip in
2 min read
Introduction to pygame
Game programming is very rewarding nowadays and it can also be used in advertising and as a teaching tool too. Game development includes mathematics, logic, physics, AI, and much more and it can be amazingly fun. In python, game programming is done in pygame and it is one of the best modules for doing so. Installing pygame: Pygame requires Python;
5 min read
PyGame Set Mouse Cursor from Bitmap
In this article, we are going to see how to set the mouse cursor from bitmap using the PyGame module in Python. What is PyGame?It is a cross-platform set of Python modules designed for writing video games.It includes computer graphics and sound libraries designed to be used with the Python programming language.It can handle time, video, music, font
5 min read
Python | Making an object jump in PyGame
Pygame is a cross-platform set of Python modules designed for writing video games. It includes computer graphics and sound libraries designed to be used with the Python programming language. Now, it’s up to the imagination or necessity of developer, what type of game he/she wants to develop using this toolkit. So, in this article, we will learn how
3 min read
Article Tags :
Practice Tags :