Setting up a blank screen

In this tutorial we will be creating the most simple project possible that just opens a blank window

Creating your first PyGame Python file

Creating a Python File in PyCharm is very simple. First right-click on the root folder of the project. Then, hover over "New" and then click on "Python File." This will prompt you for the name of the file. For now, simply use the name "window" and press enter.

Your root folder is the one that you named your project

Writing Python Code

First, in the code, you're going to import all the libraries used in the script. You can do this with a simple import statement. The following code block put all the pygame functions at your disposal.

import pygame

Then, we can create the main function:

def main():

Then, within the main function, initialize the pygame module with the following command. This will tell pygame that a game is being made and set up any properties before anything else.

pygame.init()

We now will create a window with the following command. The two arguments are the x and y scale for the canvas it will create

gameDisplay = pygame.display.set_mode((800,600))

For when you exit the game, you need a piece of code that will tell the window to close

Up to now, we've written the following code. To run it, go to run in the top bar and press Run Module.

You should see a blank window appear on the screen that looks like this ->

Last updated

Was this helpful?