Questions tagged [pygame]

Pygame is a set of Python modules designed for writing video games. Use this tag only if you are using the Pygame library and not if you have a question about programming a game in Python in general.

Pygame is a free Python library released under the Lesser General Public License (GNU LGPL) version 2.1 (according to its GitHub page), aimed at creating video games. It's built on top of , is highly portable and runs on nearly every platform and operating system.

References

Documentation

Games using Pygame

19430 questions
26
votes
8 answers

How do I get the size (width x height) of my pygame window

I have created a window using pygame.display.set_mode((width, height), pygame.OPENGL | pygame.DOUBLEBUF | pygame.RESIZABLE) Later on in the app I want to be able to ask that window its width and height so I can decide how…
Mutant Bob
  • 3,121
  • 2
  • 27
  • 52
26
votes
6 answers

Pygame Drawing a Rectangle

I'm making a game that requires knowing how to draw a rectangle in Python (3.2). I have checked lot of sources but none show exactly how to do it.
user2399874
25
votes
4 answers

Embedding a Pygame window into a Tkinter or WxPython frame

A friend and I are making a game in pygame. We would like to have a pygame window embedded into a tkinter or WxPython frame, so that we can include text input, buttons, and dropdown menus that are supported by WX or Tkinter. I have scoured the…
user2961646
25
votes
3 answers

How to get the resolution of a monitor in Pygame?

I'm just wondering if it is possible for me to get the resolution of a monitor in Pygame and then use these dimensions to create a window so that launching the program detects the monitor resolution and then automatically fits the window to the…
Ilmiont
  • 2,032
  • 4
  • 27
  • 44
25
votes
9 answers

Closing Pygame Window

I just spent a fair amount of time finding a 64-bit installation of pygame to use with python 3.3, (here) and now am trying to make a window. However, although the window opens up fine it does not close when it hit the x button. In fact, I have to…
KnightOfNi
  • 770
  • 2
  • 10
  • 17
24
votes
4 answers

How can I crop an image with Pygame?

I am learning pygame and want a graphic for a button with the three states: normal, hover, and pressed. I have an image like this one ... ... and I want to get a new Surface using a portion of it. I'm loading the image with this code: buttonStates…
dobleseis
  • 629
  • 2
  • 7
  • 12
24
votes
6 answers

Pygame: Draw single pixel

I'm looking for method that allow me to draw single pixel on display screen. For example when I click mouse, I want the position of clicked pixel to change color. I know how to read mouse pos, but I could not find simple pixel draw ( there is…
ashur
  • 4,177
  • 14
  • 53
  • 85
23
votes
6 answers

How can I make a sprite move when a key is held down?

Currently the sprite only moves one pixel every time a key is pressed. How could I cause the plumber sprite to move constantly when the left or right key is being held down? while running: setup_background() spriteimg = plumberright …
enrique2334
  • 1,021
  • 3
  • 17
  • 32
23
votes
1 answer

PyGame in a virtualenv on OS X with brew?

Can't quite figure out how to install PyGame in a virtualenv on OSX Lion. I'd really like to keep things contained in the virtualenv, if at all possible. I've tried downloading the source for PyGame and running the included setup.py in the…
notanumber
  • 6,399
  • 3
  • 20
  • 32
23
votes
9 answers

Pygame Display Position

I need the window position right after I created a pygame window: window = pygame.display.set_mode((width, height), 0, 32) pygame.init() By default, the window starts at 0,0 - but I also need x,y if the user changes the window position. Any ideas?
dmorlock
  • 1,993
  • 4
  • 18
  • 22
23
votes
4 answers

How to Change the Name of a Pygame window?

I am trying to change the name of a pygame window from "Pygame Window" to "test caption". I have tried: pygame.display.set_caption('test caption') But I don't think it is the right script.
R.T.
  • 332
  • 1
  • 2
  • 8
23
votes
2 answers

Antialiasing shapes in Pygame

I'm using Pygame to draw some things. The problem is that they have a lot of aliased edges: I want to make them softer, like this: My idea so far was to draw the shape in double size, and then use pygame.transform.smoothscale(surf, (w/2,…
kmaork
  • 5,722
  • 2
  • 23
  • 40
23
votes
4 answers

How do I blit a PNG with some transparency onto a surface in Pygame?

I'm trying to blit a PNG image onto a surface, but the transparent part of the image turns black for some reason, here's the simple code: screen = pygame.display.set_mode((800, 600), pygame.DOUBLEBUF, 32) world = pygame.Surface((800, 600),…
Eric
  • 339
  • 2
  • 4
  • 6
22
votes
5 answers

Basic networking with Pygame

I need to do some basic networking for a Pygame project. Basically, it's a 2D single player or cooperative game. The networking only needs to support two players, with one as a host. The only information that needs to be sent is the positions of…
Lightbreeze
  • 4,624
  • 3
  • 15
  • 10
22
votes
5 answers

How do you fix "Missing module docstringpylint(missing-module-docstring)"

I'm using the pygame module on VS Code and I ran into the issue where the pygame has not init member. I followed the solutions to this link. I edited the user settings and added "python.linting.pylintArgs": [ …