Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8315591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:10:00+00:00 2026-06-08T21:10:00+00:00

My version of Python is 3.2, and Pygame is 1.9.1. I followed the first

  • 0

My version of Python is 3.2, and Pygame is 1.9.1.

I followed the first part of the instructions found here: http://wiki.sheep.art.pl/Tiled%20Map%20in%20PyGame, with a few adjustments to accommodate for my own tileset:

def load_tileset(filename, width, height):
   image = pygame.image.load(filename).convert_alpha()
   imageWidth, imageHeight = image.get_size()
   tileSet = []
   for tileX in range(0, 3):
      line = []
      tileSet.append(line)
      for tileY in range(0, 3):
         rect = (tileX*width, tileY*height, width, height)
         line.append(image.subsurface(rect))
if __name__=='__main__':

   pygame.init()
   screen = pygame.display.set_mode((WIDTH, HEIGHT))
   pygame.display.set_caption('Tiled Background')
   screen.fill((240, 240, 255))
   table = load_tileset('tableset.gif', 16, 16)
   for x, row in enumerate(table):
      for y, tile in enumerate(row):
         screen.blit(tile, (x*24, y*24))
   pygame.display.flip()
   while pygame.event.wait().type != pygame.locals.QUIT:
        pass

I get the Nonetype error in for x, row in enumerate(table):*. I’ve tried various things, even moving the tileset itself, and changing the file type. I’ve also tried other codes, such as range.

I have managed to load images in the past, this is just my first time trying to use a tile set. The tile set has 9 16×16 tiles, and there is some transparency in them (hence the convert_alpha()).

So, can anyone say why I got the NoneType error here? Is it something to do with the image?
(Note, the reason there’s 3’s in the “For tileX in range” is that it wouldn’t accept the calculation as set fourth in the tutorial, so I just did the maths myself.)

  • Edit: Accidently typed: for x, row in range(table): instead of for x, row in enumerate(table): in description.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:10:01+00:00Added an answer on June 8, 2026 at 9:10 pm

    You aren’t posting the full code, or have made a mistake: there’s no for x, row in range(table) line in the code above. With this specific code, you seem to be trying to pull two variables from the range function, but it only returns one value at a time.

    You probably meant to type for x, row in enumerate(table). In that case, you need to return an object when you call table = load_tileset('tableset.gif', 16, 16) because unless any given function is explicitly told to return an object, it’ll return None and that’s why the line is giving you trouble, because the type of None is Nonetype

    Here’s an example of a function returning None and then returning a string, a returned string:

    def thisFuncReturnsNone():
       pass
    
    print 'what gets returned:', thisFuncReturnsNone()
    >>> None
    
    def thisFuncReturnsAString():
      return 'a returned string'
    
    print 'what gets returned a second time:', thisFuncReturnsAString()
    >>> a returned string
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone found a version of pywin32 for python 3.x? The latest available appears
Which was the first version of python to include the else clause for for
I read here that On Windows, your Python version must match the version used
In older version of python, 'str' object has no attribute 'format error will be
I have just started learning python version 3 and trying to create a file
I am running Cygwin Python version 2.5.2. I have a three-line source file, called
I'm working on a Python version of hangman that works off of a .txt
Is there a way to upgrade the version of Python used in a virtual
I have a linux VPS that uses an older version of python (2.4.3). This
After solving countless problems with the hg-fast-export tool on Windows (from finicky python version

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.