views:

37

answers:

1

In the config file I have the varible defined as

BackgroundColor = 0,0,0

Which should work for the screen.fill settings for Pygame or any color argument for that matter. Where I can just do screen.fill(0,0,0)

The problem I think is with this is that for integers read through a configfile I have to put int() to convert the string to an int. For something like colors int doesnt work and I have no idea what should be used.

TypeError: invalid color argument

Thats the error from python.

+2  A: 

You've got a string representing the color, e.g. '0,0,0'. Use split(',') to split it into separate fields, then convert each one.

e.g.

color = '255, 255, 255'
red, green, blue = color.split(',')
red = int(red)
green = int(green)
blue = int(blue)

Or if you want to do it in one step and the comprehensions don't bother you:

color = '128, 128, 128'
red, green, blue = [int(c) for c in color.split(',')]
dash-tom-bang
Thanks, thats exactly what I thought, nice to get that second simpler code as well :)
Elvar