i'm new to programming and have recently started coding in python. i'm working with a textbook that has codes with sample programs in it. the following code is from that book and is supposed to turn a colored picture into a black and white picture by assigning the colors black or white to every pixel depending on their brightness (the sum of their RGB-values).
from tkinter import *
def black_white ():
average = 382.5
for x in range (image.width()):
for y in range (image.height()):
c = image.get(x, y)
brightness = int(c[0]) + int(c[1]) + int(c[2])
if brightness < average:
image.put("black", (x))
else:
image.put("white", (x))
window = Tk()
image = PhotoImage(file="1.gif")
button = Button(master=window, command=black_white,
font=("Arial", 14),
text="Bearbeiten")
label = Label(master=window, image=image)
label.pack()
button.pack(fill=X)
window.mainloop()
however, the code doesn't work, the error message i get is:
Exception in Tkinter callback
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/__init__.py", line 1550, in __call__
return self.func(*args)
File "/Users/(anonymous)/Desktop/programmieren/raspberry_lehrbuch/schwarzweiß.pyw", line 8, in black_white
brightness = int(c[0]) + int(c[1]) + int(c[2])
ValueError: invalid literal for int() with base 10: ' '
i already did a bit of research but couldn't find anything that made it work. help is very much appreciated :) oh and i use a macbook pro 2010 with el capitan


int("")and you get the same error message. Checkcbefore you dobrightness = int(c[0]) + int(c[1]) + int(c[2])