我在做一个游戏,把按钮放在我的主画布上。然而,这些按钮中的每一个,无论何时绘制,都在创建另一个更小的空白画布。他们总是走在比赛的前面,非常烦人。你知道吗
有人知道我怎么能把这些按钮放在画布上,却没有其他窗口(我想它们可能是按钮通常会被绘制的默认窗口)出现吗?此外,这些窗口在关闭时会导致错误(见下文)。你知道吗
我不太清楚是什么原因造成的,我的代码超过1500行-所以我没有放入任何代码(除了我的一个按钮的代码)
btncont = Button(text = "Continue", command = Continue, anchor = W)
btncont.configure(width = 10, activebackground = "#33B5E5")
btncont_window = canvas.create_window(300, 600, anchor=NW, window=btncont)
>>> Exception in Tkinter callback
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/idlelib/run.py", line 121, in main
seq, request = rpc.request_queue.get(block=True, timeout=0.05)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/queue.py", line 175, in get
raise Empty
queue.Empty
>>>During handling of the above exception, another exception occurred:
>>>Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tkinter/__init__.py", line 1475, in __call__
return self.func(*args)
File "/Users/Admin/Desktop/NewPomg/Pong - Revolutions [Version 6.0.1].py", line 1179, in TwoPlayer
tk.update_idletasks()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tkinter/__init__.py", line 970, in update_idletasks
self.tk.call('update', 'idletasks')
_tkinter.TclError: can't invoke "update" command: application has been destroyed
如果您使用的是
create_window
,那么按钮应该是画布的子级。例如:我怀疑这是导致堆栈跟踪的原因,但这可能是问题的一部分。既然您使用的是队列,我猜您使用的是线程,而tkinter不是线程安全的。因此,如果您正在使用线程,并且您试图从多个线程在画布上绘制,这肯定是问题的一部分。你知道吗
如果你在写一些简单的东西,比如乒乓球游戏,你根本不需要线程。因此,第一步可能是删除线程并使用
after
来制作动画。在这个网站上有几个例子来说明如何做到这一点。你知道吗相关问题 更多 >
编程相关推荐