【问题标题】:_tkinter.TclError: wrong # args : What's the matter?_tkinter.TclError: 错误 #args : 怎么了?
【发布时间】:2011-04-13 00:23:04
【问题描述】:

还在写游戏。不过,这个错误有点不同。我得到了这样的回溯......

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)

在def __init__(self, mainWin): 的class Board(Canvas): 中 每件作品都有自己的tag_bind(#piece-var, '&lt;1&gt;', _onPieceClick)

我的假设是currentCommand 没有很快收到值。 你们认为造成这种痕迹的原因是什么?

【问题讨论】:

    标签: python events binding canvas tkinter


    【解决方案1】:

    您的假设几乎可以肯定是正确的。您可以通过在调用find_withtag 之前打印出该值来轻松测试此假设。

    【讨论】:

    • 是的,我不知道 tkinter 事件发生的顺序,所以我在实际将其设置为任何内容之前调用了 currentCommand。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多