titi157 titi157 - 9 months ago 31
Python Question

What does this AttributeError means ? 'int' object has no attribute 'items'

I have a problem with my function "draw_pieces()" because when i run my code, i have the following errors: (Without "draw_pieces()" my code works)

_cnfmerge: fallback due to: 'int' object is not iterable
Traceback (most recent call last):
File "C:\Users\Thierry\AppData\Local\Programs\Python\Python35\lib\tkinter\__init__.py", line 102, in _cnfmerge
TypeError: 'int' object is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Thierry\Desktop\Chess\Chessboard.py", line 31, in <module>
File "C:\Users\Thierry\Desktop\Chess\Chessboard.py", line 28, in draw_pieces
canvas.create_image=Canvas(30,30, image=photo, anchor=CENTER, state=NORMAL)
File "C:\Users\Thierry\AppData\Local\Programs\Python\Python35\lib\tkinter\__init__.py", line 2244, in __init__
Widget.__init__(self, master, 'canvas', cnf, kw)
File "C:\Users\Thierry\AppData\Local\Programs\Python\Python35\lib\tkinter\__init__.py", line 2129, in __init__
cnf = _cnfmerge((cnf, kw))
File "C:\Users\Thierry\AppData\Local\Programs\Python\Python35\lib\tkinter\__init__.py", line 105, in _cnfmerge
for k, v in c.items():
AttributeError: 'int' object has no attribute 'items'

Here is my code :

from tkinter import *

rows = 8
columns = 8
color1 = "#b35821" #Flery Orange
color2 = "#efcb9d" #New Tan
dim_square = 64

canvas=Canvas(root, width=512, height=512)


def draw_chessboard():
color = color2
for r in range(rows):
color = color1 if color == color2 else color2
for c in range(columns):
x1 = (c * dim_square)
y1 = ((7-r) * dim_square)
x2 = x1 + dim_square
y2 = y1 + dim_square
canvas.create_rectangle(x1, y1, x2, y2, fill=color, tags="area")
color = color1 if color == color2 else color2

def draw_pieces():
canvas.create_image=Canvas(30,30, image=photo, anchor=CENTER, state=NORMAL)



Can you help me to fix this ?
Thanks in advance for your help :).


I tried making this change, and the program ran without error:


canvas.create_image=Canvas(30,30, image=photo, anchor=CENTER, state=NORMAL)

change to:

canvas.create_image(30,30, image=photo, anchor=CENTER, state=NORMAL)

I also have this resource that I like to go to when I'm using tkinter. I hope this helps.