2011-04-13 5 views
0

게임을 아직 작성 중입니다. 이 오류는 약간 다릅니다. 나는 내 말은 _tkinter.TclError : wrong # args : 뭐가 문제입니까?

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에서 게임 조각 태그를 저장 한 다음 조각이 같은 바인딩으로 이동 될 때까지 특정 부분을 제어하기 위해 그 값을 사용하는 것이 었습니다 class Board(Canvas): 각 조각의 def __init__(self, mainWin):에서

canvas.bind('<1>', _newSpaceChosen) 

은이

,691,363 tag_bind(#piece-var, '<1>', _onPieceClick) 자신있어했다210

내 가설은 currentCommand이 곧 값을받지 못한다는 것입니다. 여러분이이 추적을 어떻게 생각합니까?

답변

0

당신의 가설은 거의 틀림 없습니다. find_withtag에 전화하기 전에 값을 인쇄하여이 가설을 쉽게 테스트 할 수 있습니다.

+0

그래, 나는 tkinter 이벤트가 일어난 순서를 모른다. 그래서 나는 실제로 그것을 설정하기 전에'currentCommand'라고 불렀다. 감사! – GaleDragon