2011-04-13 83 views
0

仍在寫遊戲。不過,這個錯誤有點不同。我得到一個回溯這樣的..._tkinter.TclError:錯誤#參數:這是怎麼回事?

Exception in Tkinter callback Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/tkinter/__init__.py", line 1399, in __call__ return self.func(*args) File "/Users/bluedragon1223/Desktop/Djambi0-2.py", line 68, in _newSpaceChosen pieceID = event.widget.find_withtag(currentCommand) File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/tkinte/__init__.py",
line2199, in find_withtag return self.find('withtag', tagOrId) File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/tkinter/__init__.py", line 2173, in find self.tk.call((self._w, 'find') + args)) or() _tkinter.TclError: wrong # args: should be ".23215664 find withtag tagOrId"

我的意思是,我還以爲代碼足夠無害。

我有全局變量currentCommand = None(CurX, CurY) = (0,0)(ToX, ToY) = (0,0)下手,如果有事情做吧,但主要的問題是我的事件。

有兩種:

def _newSpaceChosen(event): 
print(event.widget.find_withtag('rN')) #Used to check if I had used find_withtag correctly 
pieceID = event.widget.find_withtag(currentCommand) #This is the problem source 
[CurX, CurY] = event.widget.coords(pieceID[1]) 
print(CurX, CurY) 
[MetaToX, MetaToY] = _point2square(event.x, event.y) 
print(event.x, event.y) 
print(MetaToX, MetaToY) 
[ToX, ToY] = _square2point(MetaToX, MetaToY) 
print(ToX, ToY) 
event.widget.move(pieceID, ToX - CurX, ToY - CurY) 

def _onPieceClick(event): 
stuffTags = event.widget.gettags(event.widget.find_closest(event.x, event.y)) 
try: 
    event.widget.delete(event.widget.find_withtag('bbox')) 
except: 
    pass 
bboxULX = (event.x // 90 + 1) * 90 
bboxULY = (event.y // 90 + 1) * 90 
bboxLRX = (event.x // 90 + 1) * 90 - 90 
bboxLRY = (event.y // 90 + 1) * 90 - 90 
event.widget.create_rectangle(bboxULX,bboxULY,bboxLRX,bboxLRY, width=3, 
outline='yellow',tag='bbox') 
currentCommand = stuffTags[0] 
print(currentCommand)` 

當時的想法是遊戲卡片標籤存儲在currentCommand,然後使用該值來控制特定片,直到片綁定的移動這樣的:

canvas.bind('<1>', _newSpaceChosen) 
class Board(Canvas): 每一塊的 def __init__(self, mainWin):

有它自己的tag_bind(#piece-var, '<1>', _onPieceClick)

我的假設是currentCommand沒有及時收到價值。 你們認爲什麼導致了這種痕跡?

回答

0

你的假設幾乎肯定是正確的。在致電find_withtag之前,您可以輕鬆測試該假設。

+0

是的,我不知道tkinter事件發生的順序,所以我在實際設置任何東西之前調用了'currentCommand'。謝謝! – GaleDragon 2011-04-17 01:44:28