2016-04-16 12 views
-1

私のコードを実行すると、次のエラーが発生するので、私は "draw_pieces()"関数に問題があります:( "draw_pieces()"コードなし)このAttributeErrorとはどういう意味ですか? 'int'オブジェクトに属性 'items'がありません

ここで
_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 
    cnf.update(c) 
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> 
    draw_pieces() 
    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' 

は私のコードです:

from tkinter import * 
root=Tk() 
root.geometry("512x512") 

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

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

photo=PhotoImage(file="blackk.gif") 

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) 

draw_chessboard() 
draw_pieces() 

root.mainloop() 

は、あなたは私がこの問題を解決するのに役立つことはできますか? 事前にお手数をおかけしていただきありがとうございます:)。

+0

エラーが発生したコードを表示してください。あなたはおそらく、あなたが辞書を持っていると思うところに 'int'を持っているでしょう。編集したハイライトではなく完全なトレースバックを表示してください。 – cdarke

+1

トレースバック全体(4つのスペースでインデントされている)をコピーして質問に貼り付ける必要があります。それにもかかわらず、 'create_image'は' Canvas'ウィジェット_method_の名前なので、別の(Canvas')オブジェクトで置き換えることで何を達成しようとしているのかは不明です。 – martineau

+0

私はちょうど私のボードに作品を配置したい。 – titi157

答えて

1

私はこの変更を作ってみました、とプログラムがエラーなしで実行しました:へ

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

変更:

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

私もIこのリソースを持っています私がtkinterを使っている時に行くのが好きです。私はこれが役立つことを願っています

http://infohost.nmt.edu/tcc/help/pubs/tkinter/tkinter.pdf

+0

ありがとう、tkinterは私には直感的ではありません^^ – titi157

+0

可読性を向上させるための編集のための、Rogalskiさん、ありがとうございます! – coralvanda

関連する問題