當我嘗試運行我的程序時,出現一個奇怪的錯誤。它應該在TK()窗口上繪製一個紅色圓圈。爲什麼tkinter會給我一個「invalid command name .37395760」的錯誤?
這裏是我的代碼:
from tkinter import *
class Circle:
def __init__(self, radius, points = 0, xcoordinate = 0, ycoordinate = 0):
self.radius = radius
self.points = points
self.color = "red"
self.xcoordinate = xcoordinate
self.ycoordinate = ycoordinate
class World:
def __init__(self):
self.constructor = Tk()
self.constructor.title("Circle")
self.canvas = Canvas(self.constructor, width = 200, height = 200, borderwidth = 0, highlightthickness = 0, bg = "black")
self.canvas.grid()
self.constructor.mainloop()
def drawPlayer(self):
player = Circle(50)
self.canvas.create_oval(player.xcoordinate - player.radius, player.ycoordinate - player.radius, player.xcoordinate + player.radius, player.ycoordinate + player.radius, fill = player.color)
c = World()
c.drawPlayer()
我得到這個錯誤:
File "C:\Python34\Lib\tkinter\__init__.py", line 2318, in _create
*(args + self._options(cnf, kw))))
_tkinter.TclError: invalid command name ".37395760"
我重讀,甚至寫下了我的代碼,看看我要去哪裏錯了,但我只是找不到錯誤。
注:我運行它後出現此錯誤,並且出現一個窗口,並顯示一個黑色的畫布,但沒有圓圈。
謝謝!
我得到同樣的錯誤,你有你的代碼,但不同的浮動...我後,我得到的錯誤關閉窗戶,對你來說是一樣的嗎?還有,你跑步了嗎? ning python 2或3?我假設3,因爲我認爲tkinter是蟒蛇2中的大寫。 – Others
我發現這個問題謝謝。是的,它是在窗戶關閉後 – Katie2423