Pygame 1.9.2

I just installed Pygame 1.9.2 and am running Python 3.3. I'm having trouble figuring out how to make it so that when I click the 'X' in my pygame window, the program closes. I believe the following code works with Pygame 1.9.2 and Python 3.2, but is there any way to get it to work on Python 3.3? And what do I have to change to get the right effect? Python pygame-1.9.2pre (64-bit) is a Shareware software in the category Miscellaneous developed by Python pygame-1.9.2pre (64-bit). The latest version of Python pygame-1.9.2pre (64-bit) is currently unknown. It was initially added to our database on. Python pygame-1.9.2pre (64-bit) runs on the following operating systems: Windows. Pygame is a free and open-source programming language library that employs Python. You can use the software to make multimedia applications, including those related to art, music, sounds, videos, games, and multimedia projects. One of the greatest advantages to this.

Pygame.mixer.Sound(buffer) is new in pygame 1.8 pygame.mixer.Sound Create a new Sound object from a file or buffer object keyword arguments and array interface support new in pygame 1.9.2 play ( ) ¶ begin sound playback. Run Pygame online for free on rollApp without downloads or installation on Chromebook, laptop, desktop, iPad and Android.

It's happy dance time.
pygame 2 is out.
It looks like we're 20 years old.
ps. we have a present for you coming shortly.
Saturday April 18th to Tuesday April 21st, 2020
Starts at 3:00 AM CEST *
Join us for Ludum Dare 46, our first event of 2020!

For the next two months, I'd like to try to focus on pygame 2 critical issues.

Backwards compatibility issues people are reporting with the pygame 2 dev releases.

So there's a feature freeze on anything not related to these issues. One issue at a time until the two months are up or we are done.

The first issue is: 'SDL 2: Per Pixel Alpha error'.

Over the next weeks we have plenty of game jams that people from the pygame communities take part in.

Alakajam is first starting on September 20th. 'Alakajam! is a young community gathering game development enthusiasts from all backgrounds. We host a series of informal events, that give you a chance to both make games and get people to play them. Alakajam! competitions, taking place over a week-end, three times a year. Start/end times are suited to European timezones.'

Then the must-use-python PyWeek challenge 'Invites entrants to write a game in one week from scratch either as an individual or in a team. Is intended to be challenging and fun. Will hopefully increase the public body of python game tools, code and expertise. Will let a lot of people actually finish a game, and may inspire new projects (with ready made teams!).' PyWeek runs from Sept. 22, 2019 to Sept. 29, 2019, and theme voting is already on.

Finally, Ludum Dare is an event where you create a game from scratch in a weekend based on a theme. Saturday October 5th to Tuesday October 8th, 2019. Starts at 12:00 AM CEST *. Ludumdare is the oldest online game jam, and has the largest number of participants. There is a Jam (72h, less restrictive rules), and a compo (48h more rules). The Jam now lets people submit paper board games, and even things like crafts that aren't games at all!

Want to join in as part of a team? The pygame community game (stuntcat) is also taking part, by creating a new mini game for some of these game jams. Drop into the discord chat #communitygame channel and say hi ( https://discord.gg/r8yreB6.

Also, how about inviting women and non-binary people to make the game with you?

If you want to join in online, come into our 'Discord' #contributing channel https://discord.gg/r8yreB6. If you're at EuroPython you can find information about the sprints on their website.

Whilst we focus like a shark-lazer on pygame 2, here is a bonus pygame 1.9.6 with a couple of small regression bug fixes.
- mp3 via smpeg was missing in manylinux builds.
- mixer thread deadlock issue when controlling it from different threads.
- pygame.version.vernum now has major, minor, and patch attributes.

TLDR; Some highlights.

Every single source file has been heavily modified and moved in this release. Initial (source code only) support for SDL2 has been merged in. We also support compiling with SDL1 in the same code base, so the migration to pygame 2 is easier. pygame 2 will be released with SDL2 being the default backend when some remaining issues are ironed out. The 1.9.x releases will continue with SDL1 until then. Also, the C API of pygame is undergoing a transformation with lots of cleanups. Then there have been plenty of other cleanups all throughout the python code as well. There's still lots to clean up, but things should be significantly easier for people to contribute (👋 hello and thanks new contributors!). The documentation has been improved with better examples links, search functionality, and improved navigation. Support for older Macs, and newer Macs has been improved. The mask, midi, draw, and math modules have gotten lots of polish with rough edges removed.

Pygame 1.9.2 Download

Thanks

A very special thanks to the people who have volunteered commits to pygame since the last release. In alphabetical order...

(@alphaCTzo7G) | Amos Bastian (@amosbastian) | Andrey Lopukhov (@andreyx86) | Augusto Noronha (@augusto2112) | Bernardo Sulzbach (@bernardosulzbach) | (@Bottersnike) | Cai Q.T. (@CAIQT) | (@Cerealdragon) | Charles (@charlesej) | (@ChrisWeissNike) | (@cmtrapp02) | Daniel Molina (@daniel-molina) | David Caughell (@DavidCaughell) | David Lönnhager (@dlon) | (@dr0id) | burmer (@dtschirmer) | (@e1000) | xFly_Dragon (@husano896) | (@IchMageBaume) | René Dudfield (@illume) | (@LambdaGoblin) | Lenard Lindstrom (@llindstrom) | François Magimel (@Linkid) | (@LiquidFenrir) | Mark Hurley (@markph0204) | Marius Gedminas (@mgedmin) | (@metulburr) | Michael Farrell (@micolous) | Dominik George (@Natureshadow) | Nik (@nikolas) | Nunu-Willump (@Nunu-Willump) | (@pleboulanger) | Rebecca Chen (@rchen152) | (@robertpfeiffer) | Sett (@sw00) |

Quite a few new people have helped out with this release 🤗

An equally special thanks to everyone else who has contributed in other ways. Thanks to claudeb, imallet, and deshipu for moderating the discord chat to keep it friendly. Thanks to the twitter folk, and the stackoverflow Q&A people. Thanks to everyone who puts their game up on the pygame website for others to look at. Thanks to people making tutorials and sharing articles & books they've written. Thanks to the r/pygame mods and community. Thanks to pyladies groups for running fun sessions, and for making things better. Thanks to the teachers providing feedback, and for doing something fun with their students. Thanks to Debian, Raspberrypi, Arch, Fedora, and all the other community groups. 🖤

More details.

#945 Vector: Explain slices and swizzling
#944 Update surface documentation
#937 Make mask offset boundary checking consistent
#936 Update midi documentation
#931 Fix drawing 1 pixel wide off-surface ellipses
#929 Use SDL_RWops instead of pg_FopenUTF8.
#928 Fix LayeredDirty's inconsistent use of its source rect
#927 Workaround for locale errors with PyPy
#926 Update dependencies for manylinux builds.
#924 Upload .whl binaries to a github draft release when creating tag.
#923 Update scrap documentation
#922#881#879 Fix zero-sized mask segfaults
#920 Fix the SystemError when no type specific clipboard content exists.
#917 Update scrap tests
#914 Update freetype tests
#911#893#889#876#874#844#840#831#819 Improved mask tests
#900 Add sprite tests
#899 bugfix for dirty sprite when using a source rect
#891 Add missing Vector2.magnitude()
#873 Fix mask index out of bounds segmentation fault
#806 Mask constructor 'fill' argument
#807 Use version directives consistently in documentation and update style
#805 Event functions: pump parameter and keyword arguments
#803 Add customized repr()/str() output for Mask objects
#802 Fix aaline()/aalines() not drawing on a surface's border
#797 Keep surface alpha value for copied surfaces with SRCALPHA flag
#760#707 Load images on multiple threads properly
#783 Fix overlap_mask() making incorrect mask
#751#749#748#746#745 Added get_init() to all modules with an init() function
#725 Allow camera module to be used on Windows
#722 API version macros
#698 Use pre styles in docs
#670 Converting between ANSI notes and MIDI notes or frequencies
#663 Compile for PyPy 3 and PyPy fixes
#665 Chimp tutorial: reindent and clean some code
#664 Chimp tutorial: fix reST syntax
#656#649 Handle Unicode objects and paths properly
#631 Fix failing tests test_aapolygon and test_pie
#630 Fix freetype rotation rendering
#596 aaline cleanup
#582 draw.aaline: blend correctly
#577#573 Fixed FreeType memory leaks
#571 Fix surface.blits() bugs

#560 Added math.Vector2 subclass test for issue
#558 Raise TypeError on invalid point arguments
#557 Update typecheck to allow subtypes
#545 update system font lists in sysfont.py
#538 Mac fonts support using system_profiler
#559 Allow clean silencing of support prompt
#553 Fix homebrew travis mac builds
#551 Fixed freezing while playing music from file objects
#550 updated for python 3
#546 Improve message on failed imports & cleanup
#544 Spelling fix in examples/glcube.py
#540 DirtySprite subclass allow other _layer values
#536 dependency version into README & Cleanup SDL1.2
#534 More test cleanups.
#535 draw_py for Python algos & aaline testing
#534 More Test cleanup
#518 Organise the docs modules by usage, add search form.
#517 Test cleanup n+1 : yet another test cleanup branch
#516 PY_VERSION_HEX < 0x02070000 : cleanup
#515 Fix draw polygon ; tests & code cleanup
#514 Cleanup Python < 2.7 references
#511 Fix odd-width ellipses not drawing correctly
#510 Update unit tests draw.ellipse, add unit tests draw.(aa)line(s)
#509 Midi tests : add, refactor, cleanup
#508 More test method cleanup
#507 Improve mac compile times on travis.
#505 Remove 'if 1:' pattern in tests
#504 Cleanup mixer test
#503 Clang format all the src_c/.c files
#502 Cleanup some test methods & test/sndarray_test.py
#501 Add draw_ellipse unit test
#500 Test for overlap mask
#499 Remove boilerplate imports from top of test files
#498 Adding a test for Thick Line Bug
#493 0 sized masks are now possible
#489 transform.scale does not crash for zero sized surfaces
#488 Added unit test 'test_zero_surface_transform' for issue 411
#486 Moved jquery.plugin.docscomments.js into pygameweb.
#485 Repo cleanup. 8 things in top level. Rest in buildconfig/. Old stuff removed.
#484 Added mac sdl2 support. Changed config.py -sdl2
#483 Support older mac core duo 2 cpus
#482 The giant SDL2_patches merging PR.
#476 Do not try to add portmidi on freebsd. It does not exist.
#475 Resurrect Python 3.4 builds on Appveyor

🐱‍🏍 stuntcat is our open source mini-game we worked on in order to drive pygame 2 development forward. We wanted to make a real mini-game and try to release it for sale on as many platforms as possible. So that other people can look at the source code and distribute their game on more platforms too.

We only had 4 days... but during that time more than 14 people got involved. We learnt a lot during this. The compilation instructions for pygame 2 were improved so that more people could build development versions. We automated the installer generation for Windows, Mac, and pypi on github (so other projects can copy this base-code and do it too). Gif animation saving was started (because when you release your game you want a gif right?). Missing features and areas where documentation could be improved were identified (animated sprites, and scenes anyone?). Fixes to pymunk (a great 2D physics engine) were made so distributing physics games to end users is now easier. There's also an example of using the tile map loader (PyTMX) with the physics engine. More than a month after the game jam finished we are working on issues discovered during the making of 🐱‍🏍 stuntcat.

We want to make distributing pygame apps easier for people. You made your game, now you want to share it with your friends or even sell it right? The first place we made a release was on itch.io, a platform for selling games and apps. There we uploaded the Mac, Windows, and source for people to download with a pay-what-you-feel option.

Next step is to release the game on Steam (another popular games platform). For the next step we need to raise $100 for the Steam App fee. We also have to make the game better! It's already a pretty fun mini game, but requires more mini games and more polish. We also need to make pygame 2 pre-release binaries so that we can actually publish on Steam.

Thanks to the makers of stuntcat: bitcraft, blubberquark, Bottersnake, claudeb, illume, Kuba | ThePolish, TJWhale, hfoxp, xeno, M, CaptHurls, dlon, dirk0, viblo, and kleines filmröllchen.


day 0: $0 of $100 raised for Steam app fee.
day 1: $5 of $100
day 2: $57 of $100
day 3: $100 of $113.20
day 14: $107 of $113.20
day 20: $127 of $113.20
If you ever wanted to support pygame development financially and you can afford it, this is how you can by purchasing stuntcat on itch.io for $2 or what ever you feel. update: we raised enough to make a steam release. Thanks to everyone who chipped in!

See the post on the PyPy blog: 'PyPy for low latency systems',

and also this post: Experiments with new low latency PyPy garbage collector in a thread.

welcome to our humble (and slightly strange) little part of the World Wide Web. Let me give you a quick introduction about what you've stumbled upon here.

pygame (the library) is a Free and Open Source python programming language library for making multimedia applications like games.

pygame.org (the website) welcomes all Python game, art, music, sound, video and multimedia projects. Once you have finished getting started you could add a new project or learn about pygame by reading the docs. For more information on what is happening in the pygame world see the community dashboard web page, which lists many things like our projects we are working on, news (our blog with rss), twitter, reddit (forum), stackoverflow (Q&A), Bitbucket (development), irc(chat), mailinglist (we love writing electronic mail to each other) and other various bits and pieces about pygame from around the internets.

pygame (the community) is a small volunteer group of creative humans who ♥ making things (there may also be a few cats, several koalas, dozens of doggos, 3.14 gnomes, and 42 robots who also tinker amongst us). We respect each other, and follow the Python community code of conduct, whilst we help each other make interesting things.

Enjoy yourself whilst looking around. We look forward to your creations.


Best humanly possible wishes and extra toasty warm regards,
pygame

ps. We spell colour without the u (sorry), and we always spell pygame with lower case letters. Also, please do excuse the mess - we're doing some renovations around here you see.

Surface((width, height), flags=0, depth=0, masks=None) -> Surface
Surface((width, height), flags=0, Surface) -> Surface

A pygame Surface is used to represent any image. The Surface has a fixed resolution and pixel format. Surfaces with 8-bit pixels use a color palette to map to 24-bit color.

Call to create a new image object. The Surface will be cleared to all black. The only required arguments are the sizes. With no additional arguments, the Surface will be created in a format that best matches the display Surface.

The pixel format can be controlled by passing the bit depth or an existing Surface. The flags argument is a bitmask of additional features for the surface. You can pass any combination of these flags:

Both flags are only a request, and may not be possible for all displays and formats.

Advance users can combine a set of bitmasks with a depth value. The masks are a set of 4 integers representing which bits in a pixel will represent each color. Normal Surfaces should not require the masks argument.

Surfaces can have many extra attributes like alpha planes, colorkeys, source rectangle clipping. These functions mainly effect how the Surface is blitted to other Surfaces. The blit routines will attempt to use hardware acceleration when possible, otherwise they will use highly optimized software blitting methods.

Pygame 1.9.2 Download

There are three types of transparency supported in pygame: colorkeys, surface alphas, and pixel alphas. Surface alphas can be mixed with colorkeys, but an image with per pixel alphas cannot use the other modes. Colorkey transparency makes a single color value transparent. Any pixels matching the colorkey will not be drawn. The surface alpha value is a single value that changes the transparency for the entire image. A surface alpha of 255 is opaque, and a value of 0 is completely transparent.

Per pixel alphas are different because they store a transparency value for every pixel. This allows for the most precise transparency effects, but it also the slowest. Per pixel alphas cannot be mixed with surface alpha and colorkeys.

There is support for pixel access for the Surfaces. Pixel access on hardware surfaces is slow and not recommended. Pixels can be accessed using the get_at() and set_at() functions. These methods are fine for simple access, but will be considerably slow when doing of pixel work with them. If you plan on doing a lot of pixel level work, it is recommended to use a , which gives an array like view of the surface. For involved mathematical manipulations try the module (It's quite quick, but requires NumPy.)

Any functions that directly access a surface's pixel data will need that surface to be lock()'ed. These functions can lock() and unlock() the surfaces themselves without assistance. But, if a function will be called many times, there will be a lot of overhead for multiple locking and unlocking of the surface. It is best to lock the surface manually before making the function call many times, and then unlocking when you are finished. All functions that need a locked surface will say so in their docs. Remember to leave the Surface locked only while necessary.

Surface pixels are stored internally as a single number that has all the colors encoded into it. Use the map_rgb() and unmap_rgb() to convert between individual red, green, and blue values into a packed integer for that Surface.

Surfaces can also reference sections of other Surfaces. These are created with the subsurface() method. Any change to either Surface will effect the other.

Each Surface contains a clipping area. By default the clip area covers the entire Surface. If it is changed, all drawing operations will only effect the smaller area.

blit(source, dest, area=None, special_flags=0) -> Rect

Draws a source Surface onto this Surface. The draw can be positioned with the dest argument. Dest can either be pair of coordinates representing the upper left corner of the source. A Rect can also be passed as the destination and the topleft corner of the rectangle will be used as the position for the blit. The size of the destination rectangle does not effect the blit.

An optional area rectangle can be passed as well. This represents a smaller portion of the source Surface to draw.

New in pygame 1.8: Optional special_flags: BLEND_ADD, BLEND_SUB, BLEND_MULT, BLEND_MIN, BLEND_MAX.

New in pygame 1.8.1: Optional special_flags: BLEND_RGBA_ADD, BLEND_RGBA_SUB, BLEND_RGBA_MULT, BLEND_RGBA_MIN, BLEND_RGBA_MAXBLEND_RGB_ADD, BLEND_RGB_SUB, BLEND_RGB_MULT, BLEND_RGB_MIN, BLEND_RGB_MAX.

The return rectangle is the area of the affected pixels, excluding any pixels outside the destination Surface, or outside the clipping area.

Pixel alphas will be ignored when blitting to an 8 bit Surface.

For a surface with colorkey or blanket alpha, a blit to self may give slightly different colors than a non self-blit.

blits(blit_sequence=(source, dest), ...), doreturn=1) -> [Rect, ...] or None
blits((source, dest, area), ...)) -> [Rect, ...]
blits((source, dest, area, special_flags), ...)) -> [Rect, ...]

Draws many surfaces onto this Surface. It takes a sequence as input, with each of the elements corresponding to the ones of blit(). It needs at minimum a sequence of (source, dest).

Parameters:
  • blit_sequence -- a sequence of surfaces and arguments to blit them, they correspond to the blit() arguments
  • doreturn -- if True, return a list of rects of the areas changed, otherwise return None
Returns:

a list of rects of the areas changed if doreturn is True, otherwise None

Return type:

list or None

New in pygame 1.9.4.

convert(Surface=None) -> Surface
convert(depth, flags=0) -> Surface
convert(masks, flags=0) -> Surface

change the pixel format of an image

Creates a new copy of the Surface with the pixel format changed. The new pixel format can be determined from another existing Surface. Otherwise depth, flags, and masks arguments can be used, similar to the call.

If no arguments are passed the new Surface will have the same pixel format as the display Surface. This is always the fastest format for blitting. It is a good idea to convert all Surfaces before they are blitted many times.

The converted Surface will have no pixel alphas. They will be stripped if the original had them. See convert_alpha() for preserving or creating per-pixel alphas.

The new copy will have the same class as the copied surface. This lets as Surface subclass inherit this method without the need to override, unless subclass specific instance attributes also need copying.

convert_alpha(Surface) -> Surface
convert_alpha() -> Surface

change the pixel format of an image including per pixel alphas

Creates a new copy of the surface with the desired pixel format. The new surface will be in a format suited for quick blitting to the given format with per pixel alpha. If no surface is given, the new surface will be optimized for blitting to the current display.

Unlike the convert() method, the pixel format for the new image will not be exactly the same as the requested source, but it will be optimized for fast alpha blitting to the destination.

As with convert() the returned surface has the same class as the converted surface.

copy() -> Surface

Makes a duplicate copy of a Surface. The new surface will have the same pixel formats, color palettes, transparency settings, and class as the original. If a Surface subclass also needs to copy any instance specific attributes then it should override copy().

fill(color, rect=None, special_flags=0) -> Rect

fill Surface with a solid color

Fill the Surface with a solid color. If no rect argument is given the entire Surface will be filled. The rect argument will limit the fill to a specific area. The fill will also be contained by the Surface clip area.

The color argument can be either a RGB sequence, a RGBA sequence or a mapped color index. If using RGBA, the Alpha (A part of RGBA) is ignored unless the surface uses per pixel alpha (Surface has the SRCALPHA flag).

New in pygame 1.8: Optional special_flags: BLEND_ADD, BLEND_SUB, BLEND_MULT, BLEND_MIN, BLEND_MAX.

New in pygame 1.8.1: Optional special_flags: BLEND_RGBA_ADD, BLEND_RGBA_SUB, BLEND_RGBA_MULT, BLEND_RGBA_MIN, BLEND_RGBA_MAXBLEND_RGB_ADD, BLEND_RGB_SUB, BLEND_RGB_MULT, BLEND_RGB_MIN, BLEND_RGB_MAX.

This will return the affected Surface area.

scroll(dx=0, dy=0) -> None

Move the image by dx pixels right and dy pixels down. dx and dy may be negative for left and up scrolls respectively. Areas of the surface that are not overwritten retain their original pixel values. Scrolling is contained by the Surface clip area. It is safe to have dx and dy values that exceed the surface size.

New in pygame 1.9.

set_colorkey(Color, flags=0) -> None
set_colorkey(None) -> None

Set the current color key for the Surface. When blitting this Surface onto a destination, any pixels that have the same color as the colorkey will be transparent. The color can be an RGB color or a mapped color integer. If None is passed, the colorkey will be unset.

The colorkey will be ignored if the Surface is formatted to use per pixel alpha values. The colorkey can be mixed with the full Surface alpha value.

The optional flags argument can be set to pygame.RLEACCEL to provide better performance on non accelerated displays. An RLEACCEL Surface will be slower to modify, but quicker to blit as a source.

get_colorkey() -> RGB or None

Get the current transparent colorkey

Return the current colorkey value for the Surface. If the colorkey is not set then None is returned.

set_alpha(value, flags=0) -> None
set_alpha(None) -> None

Set the current alpha value for the Surface. When blitting this Surface onto a destination, the pixels will be drawn slightly transparent. The alpha value is an integer from 0 to 255, 0 is fully transparent and 255 is fully opaque. If None is passed for the alpha value, then alpha blending will be disabled, including per-pixel alpha.

This value is different than the per pixel Surface alpha. For a surface with per pixel alpha, blanket alpha is ignored and None is returned.

Changed in pygame 2.0: per-surface alpha can be combined with per-pixel alpha.

The optional flags argument can be set to pygame.RLEACCEL to provide better performance on non accelerated displays. An RLEACCEL Surface will be slower to modify, but quicker to blit as a source.

get_alpha() -> int_value

Return the current alpha value for the Surface.

lock() -> None

Pygame
lock the Surface memory for pixel access

Lock the pixel data of a Surface for access. On accelerated Surfaces, the pixel data may be stored in volatile video memory or nonlinear compressed forms. When a Surface is locked the pixel memory becomes available to access by regular software. Code that reads or writes pixel values will need the Surface to be locked.

Pygame 1.9.2 download

Surfaces should not remain locked for more than necessary. A locked Surface can often not be displayed or managed by pygame.

Not all Surfaces require locking. The mustlock() method can determine if it is actually required. There is no performance penalty for locking and unlocking a Surface that does not need it.

All pygame functions will automatically lock and unlock the Surface data as needed. If a section of code is going to make calls that will repeatedly lock and unlock the Surface many times, it can be helpful to wrap the block inside a lock and unlock pair.

It is safe to nest locking and unlocking calls. The surface will only be unlocked after the final lock is released.

unlock() -> None

Unlock the Surface pixel data after it has been locked. The unlocked Surface can once again be drawn and managed by pygame. See the lock() documentation for more details.

All pygame functions will automatically lock and unlock the Surface data as needed. If a section of code is going to make calls that will repeatedly lock and unlock the Surface many times, it can be helpful to wrap the block inside a lock and unlock pair.

It is safe to nest locking and unlocking calls. The surface will only be unlocked after the final lock is released.

mustlock() -> bool

test if the Surface requires locking

Returns True if the Surface is required to be locked to access pixel data. Usually pure software Surfaces do not require locking. This method is rarely needed, since it is safe and quickest to just lock all Surfaces as needed.

All pygame functions will automatically lock and unlock the Surface data as needed. If a section of code is going to make calls that will repeatedly lock and unlock the Surface many times, it can be helpful to wrap the block inside a lock and unlock pair.

get_locked() -> bool

Returns True when the Surface is locked. It doesn't matter how many times the Surface is locked.

get_locks() -> tuple

Gets the locks for the Surface

Returns the currently existing locks for the Surface.

get_at((x, y)) -> Color

Return a copy of the RGBA Color value at the given pixel. If the Surface has no per pixel alpha, then the alpha value will always be 255 (opaque). If the pixel position is outside the area of the Surface an IndexError exception will be raised.

Getting and setting pixels one at a time is generally too slow to be used in a game or realtime situation. It is better to use methods which operate on many pixels at a time like with the blit, fill and draw methods - or by using /.

This function will temporarily lock and unlock the Surface as needed.

New in pygame 1.9: Returning a Color instead of tuple. Use tuple(surf.get_at((x,y))) if you want a tuple, and not a Color. This should only matter if you want to use the color as a key in a dict.

set_at((x, y), Color) -> None

Set the RGBA or mapped integer color value for a single pixel. If the Surface does not have per pixel alphas, the alpha value is ignored. Setting pixels outside the Surface area or outside the Surface clipping will have no effect.

Getting and setting pixels one at a time is generally too slow to be used in a game or realtime situation.

This function will temporarily lock and unlock the Surface as needed.

get_at_mapped((x, y)) -> Color

get the mapped color value at a single pixel

Return the integer value of the given pixel. If the pixel position is outside the area of the Surface an IndexError exception will be raised.

This method is intended for pygame unit testing. It unlikely has any use in an application.

This function will temporarily lock and unlock the Surface as needed.

get_palette() -> [RGB, RGB, RGB, ...]

get the color index palette for an 8-bit Surface

Return a list of up to 256 color elements that represent the indexed colors used in an 8-bit Surface. The returned list is a copy of the palette, and changes will have no effect on the Surface.

Returning a list of Color(withlength3) instances instead of tuples.

get_palette_at(index) -> RGB

get the color for a single entry in a palette

Returns the red, green, and blue color values for a single index in a Surface palette. The index should be a value from 0 to 255.

New in pygame 1.9: Returning Color(withlength3) instance instead of a tuple.

set_palette([RGB, RGB, RGB, ...]) -> None

Set the full palette for an 8-bit Surface. This will replace the colors in the existing palette. A partial palette can be passed and only the first colors in the original palette will be changed.

This function has no effect on a Surface with more than 8-bits per pixel.

set_palette_at(index, RGB) -> None

set the color for a single index in an 8-bit Surface palette

Set the palette value for a single entry in a Surface palette. The index should be a value from 0 to 255.

This function has no effect on a Surface with more than 8-bits per pixel.

map_rgb(Color) -> mapped_int

Convert an RGBA color into the mapped integer value for this Surface. The returned integer will contain no more bits than the bit depth of the Surface. Mapped color values are not often used inside pygame, but can be passed to most functions that require a Surface and a color.

See the Surface object documentation for more information about colors and pixel formats.

unmap_rgb(mapped_int) -> Color

convert a mapped integer color value into a Color

Convert an mapped integer color into the RGB color components for this Surface. Mapped color values are not often used inside pygame, but can be passed to most functions that require a Surface and a color.

See the Surface object documentation for more information about colors and pixel formats.

set_clip(rect) -> None
set_clip(None) -> None

Each Surface has an active clipping area. This is a rectangle that represents the only pixels on the Surface that can be modified. If None is passed for the rectangle the full Surface will be available for changes.

The clipping area is always restricted to the area of the Surface itself. If the clip rectangle is too large it will be shrunk to fit inside the Surface.

get_clip() -> Rect

get the current clipping area of the Surface

Return a rectangle of the current clipping area. The Surface will always return a valid rectangle that will never be outside the bounds of the image. If the Surface has had None set for the clipping area, the Surface will return a rectangle with the full area of the Surface.

subsurface(Rect) -> Surface

Returns a new Surface that shares its pixels with its new parent. The new Surface is considered a child of the original. Modifications to either Surface pixels will effect each other. Surface information like clipping area and color keys are unique to each Surface.

The new Surface will inherit the palette, color key, and alpha settings from its parent.

It is possible to have any number of subsurfaces and subsubsurfaces on the parent. It is also possible to subsurface the display Surface if the display mode is not hardware accelerated.

See get_offset() and get_parent() to learn more about the state of a subsurface.

A subsurface will have the same class as the parent surface.

get_parent() -> Surface

Pygame 1.9.2
find the parent of a subsurface

Returns the parent Surface of a subsurface. If this is not a subsurface then None will be returned.

get_abs_parent() -> Surface

Returns the parent Surface of a subsurface. If this is not a subsurface then this surface will be returned.

get_offset() -> (x, y)

find the position of a child subsurface inside a parent

Get the offset position of a child subsurface inside of a parent. If the Surface is not a subsurface this will return (0, 0).

get_abs_offset() -> (x, y)

find the absolute position of a child subsurface inside its top level parent

Get the offset position of a child subsurface inside of its top level parent Surface. If the Surface is not a subsurface this will return (0, 0).

get_size() -> (width, height)

Return the width and height of the Surface in pixels.

get_width() -> width

get the width of the Surface

Return the width of the Surface in pixels.

get_height() -> height

Return the height of the Surface in pixels.

get_rect(**kwargs) -> Rect

get the rectangular area of the Surface

Returns a new rectangle covering the entire surface. This rectangle will always start at (0, 0) with a width and height the same size as the image.

You can pass keyword argument values to this function. These named values will be applied to the attributes of the Rect before it is returned. An example would be mysurf.get_rect(center=(100,100)) to create a rectangle for the Surface centered at a given position.

get_bitsize() -> int

Returns the number of bits used to represent each pixel. This value may not exactly fill the number of bytes used per pixel. For example a 15 bit Surface still requires a full 2 bytes.

get_bytesize() -> int

get the bytes used per Surface pixel

Return the number of bytes used per pixel.

get_flags() -> int

Returns a set of current Surface features. Each feature is a bit in the flags bitmask. Typical flags are HWSURFACE, RLEACCEL, SRCALPHA, and SRCCOLORKEY.

Here is a more complete list of flags. A full list can be found in SDL_video.h

Available for

Used internally (read-only)

get_pitch() -> int

get the number of bytes used per Surface row

Return the number of bytes separating each row in the Surface. Surfaces in video memory are not always linearly packed. Subsurfaces will also have a larger pitch than their real width.

This value is not needed for normal pygame usage.

get_masks() -> (R, G, B, A)

the bitmasks needed to convert between a color and a mapped integer

Returns the bitmasks used to isolate each color in a mapped integer.

This value is not needed for normal pygame usage.

set_masks((r,g,b,a)) -> None

set the bitmasks needed to convert between a color and a mapped integer

This is not needed for normal pygame usage.

get_shifts() -> (R, G, B, A)

the bit shifts needed to convert between a color and a mapped integer

Returns the pixel shifts need to convert between each color and a mapped integer.

This value is not needed for normal pygame usage.

set_shifts((r,g,b,a)) -> None

Pygame-1.9.2a0.win32-py3.4.exe

sets the bit shifts needed to convert between a color and a mapped integer

This is not needed for normal pygame usage.

get_losses() -> (R, G, B, A)

the significant bits used to convert between a color and a mapped integer

Return the least significant number of bits stripped from each color in a mapped integer.

This value is not needed for normal pygame usage.

get_bounding_rect(min_alpha = 1) -> Rect

Returns the smallest rectangular region that contains all the pixels in the surface that have an alpha value greater than or equal to the minimum alpha value.

This function will temporarily lock and unlock the Surface as needed.

New in pygame 1.8.

get_view(<kind>='2') -> BufferProxy

Pygame‑1.9.2a0‑cp35‑none‑win32.whl

Return an object which exports a surface's internal pixel buffer as a C level array struct, Python level array interface or a C level buffer interface. The pixel buffer is writeable. The new buffer protocol is supported for Python 2.6 and up in CPython. The old buffer protocol is also supported for Python 2.x. The old buffer data is in one segment for kind '0', multi-segment for other buffer view kinds.

The kind argument is the length 1 string '0', '1', '2', '3', 'r', 'g', 'b', or 'a'. The letters are case insensitive; 'A' will work as well. The argument can be either a Unicode or byte (char) string. The default is '2'.

'0' returns a contiguous unstructured bytes view. No surface shape information is given. A ValueError is raised if the surface's pixels are discontinuous.

'1' returns a (surface-width * surface-height) array of continuous pixels. A ValueError is raised if the surface pixels are discontinuous.

'2' returns a (surface-width, surface-height) array of raw pixels. The pixels are surface-bytesize-d unsigned integers. The pixel format is surface specific. The 3 byte unsigned integers of 24 bit surfaces are unlikely accepted by anything other than other pygame functions.

'3' returns a (surface-width, surface-height, 3) array of RGB color components. Each of the red, green, and blue components are unsigned bytes. Only 24-bit and 32-bit surfaces are supported. The color components must be in either RGB or BGR order within the pixel.

'r' for red, 'g' for green, 'b' for blue, and 'a' for alpha return a (surface-width, surface-height) view of a single color component within a surface: a color plane. Color components are unsigned bytes. Both 24-bit and 32-bit surfaces support 'r', 'g', and 'b'. Only 32-bit surfaces with SRCALPHA support 'a'.

The surface is locked only when an exposed interface is accessed. For new buffer interface accesses, the surface is unlocked once the last buffer view is released. For array interface and old buffer interface accesses, the surface remains locked until the BufferProxy object is released.

New in pygame 1.9.2.

get_buffer() -> BufferProxy

acquires a buffer object for the pixels of the Surface.

Return a buffer object for the pixels of the Surface. The buffer can be used for direct pixel access and manipulation. Surface pixel data is represented as an unstructured block of memory, with a start address and length in bytes. The data need not be contiguous. Any gaps are included in the length, but otherwise ignored.

This method implicitly locks the Surface. The lock will be released when the returned object is garbage collected.

Pygame 1.9.2

_pixels_address -> int

pixel buffer address

Pygame 1.9.2a0

The starting address of the surface's raw pixel bytes.


Pygame 1.9.2

Edit on GitHub

© Pygame Developers.
Licensed under the GNU LGPL License version 2.1.
https://www.pygame.org/docs/ref/surface.html