Python 为什么特金特给我一个“答案”;无效的命令名。37395760“;错误?

Python 为什么特金特给我一个“答案”;无效的命令名。37395760“;错误?,python,tkinter,Python,Tkinter,当我试图运行我的程序时,我遇到了一个奇怪的错误。它应该在TK()窗口上画一个红色圆圈 这是我的密码: from tkinter import * class Circle: def __init__(self, radius, points = 0, xcoordinate = 0, ycoordinate = 0): self.radius = radius self.points = points self.color = "

当我试图运行我的程序时,我遇到了一个奇怪的错误。它应该在TK()窗口上画一个红色圆圈

这是我的密码:

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"
我已经重读,甚至写下了我的代码,看看哪里出错了,但我就是找不到错误

注意:此错误发生在我运行它之后,一个窗口显示为黑色画布,但没有圆圈。

谢谢大家!

一旦mainloop退出(
self.constructor.mainloop()
),小部件就不再存在。当您执行
self.canvas.create_oval(…)
(由
c.drawPlayer()
触发)时,您正试图访问已删除的小部件

Tkinter根本不允许您在主窗口被破坏后访问小部件


调用
mainloop()
在完成绘制元素后。

我在代码中得到与您相同的错误,但不同的浮点数…我在关闭窗口后得到错误,这对您来说是一样的吗?另外,您运行的是python 2还是python 3?我假设是3,因为我认为tkinter在python 2中是大写的。我发现了问题,谢谢。是的,是在窗口cl之后奥塞德