TokyoGaijin
TokyoGaijin

Reputation: 1

pygame problems - 'NoneType' object has no attribute 'fill'

Okay this one's a bit strange.

I admit I'm brand new to Python but not to programming so I've tried all different kinds of methods to find an answer to this problem but have come up with nothing.

I won't bore you with the sloppy coding that I've done but in the end I go to use the code gameDisplay.fill((0,0,0)) and I come up with the error 'NoneType' object has no attribute 'fill' on the shell.

I've tried moving the gameDisplay code around and then ran the commands in the shell to see it all live. On two machines (one ubuntu Linux one Mac). The shell results worked. However, when I double-checked and triple-checked the master code again, I got that NoneType error.

So just to make sure I didn't make a mistake in the code, I went in and did a very simple program.

import pygame

pygame.init()

screenW = 900
screenH = 600
screen = ((screenW,screenH))
gameDisplay = pygame.display.set_mode(screen)
gameDisplay = pygame.display.set_caption('MyArea')
gameDisplay.fill((255,0,0))
pygame.display.update()

So at this point, when I run the code, I should come up with a rectangular window titled "MyArea" and it should be painted red.

It's a black window, correctly captioned, with 'NoneType' object has no attribute 'fill' in the shell.

So at this point I know it's nothing I've done wrong. I've put this exact sequence into the shell directly and, live, I got the 900,600 long rectangle window titled "MyArea", painted red after I called the update function.

What gives?

Upvotes: 0

Views: 2752

Answers (1)

Nick Jarvis
Nick Jarvis

Reputation: 131

Similar to Iausek's comment, replace

gameDisplay = pygame.display.set_caption('MyArea')

with:

pygame.display.set_caption('MyArea').

pygame.display.set_caption(caption) returns None, and just modifies the current window's caption. According to the docs:

If the display has a window title, this function will change the name on the window. Some systems support an alternate shorter title to be used for minimized displays.

Upvotes: 2

Related Questions