Python 属性错误:';int';对象没有属性';tk';
我基本上是在尝试持续更新tkinter GUI窗口中嵌入的图形,并在指定时间(10 ms)后使用after函数调用update函数。然而,在执行回调时,我遇到了上述错误,而且我对tkinter和Python OOP非常陌生,因此我很可能会犯一个基本错误。以下是代码(def update_plot中发生错误): 完全回溯错误为:Python 属性错误:';int';对象没有属性';tk';,python,oop,tkinter,tk,Python,Oop,Tkinter,Tk,我基本上是在尝试持续更新tkinter GUI窗口中嵌入的图形,并在指定时间(10 ms)后使用after函数调用update函数。然而,在执行回调时,我遇到了上述错误,而且我对tkinter和Python OOP非常陌生,因此我很可能会犯一个基本错误。以下是代码(def update_plot中发生错误): 完全回溯错误为: Exception in Tkinter callback Traceback (most recent call last): File "/Users/.../a
Exception in Tkinter callback
Traceback (most recent call last):
File "/Users/.../anaconda/lib/python3.5/tkinter/__init__.py", line 1550, in __call__
return self.func(*args)
File "./gui2.py", line 202, in read_data
self.update_plot()
File "./gui2.py", line 211, in update_plot
func_id = tk.Tk.after(samplerate, self.update_plot)
File "/Users/.../anaconda/lib/python3.5/tkinter/__init__.py", line 592, in after
self.tk.call('after', ms)
AttributeError: 'int' object has no attribute 'tk'
我在这一点上很困惑,在其他地方也没有发现类似的问题。有什么建议吗?您的问题似乎出现在您的after声明中
tk.tk
不是你想象的那样
使用after()
时,通常将其应用于root
窗口,或者在类中更经常地应用于self
因此,改变:
tk.Tk.after(samplerate, self.update_plot)
致:
你的问题似乎出现在你的事后陈述中
tk.tk
不是你想象的那样
使用after()
时,通常将其应用于root
窗口,或者在类中更经常地应用于self
因此,改变:
tk.Tk.after(samplerate, self.update_plot)
致:
错误被抛出到哪一行?编辑:刚刚看到您的编辑请提供完整的回溯错误。Tkinter回调回溯中的异常(最近一次调用):文件“/Users/../anaconda/lib/python3.5/Tkinter/uuu init_uuuuuuuuuuuuuuuy.py”,调用返回self.func(*args)文件“/gui2.py”,第202行,在read\u data self.update\u plot()文件“/gui2.py”,第211行,在update\u plot func\u id=tk.tk.after(samplerate,self.update\u plot)文件“/Users/../anaconda/lib/python3.5/tkinter/\uu init\uuuuu.py”第592行的after self.tk.call('after',ms)AttributeError:'int'对象在您的问题中没有属性'tk',而不是注释lol.change
func\u id=tk.after(samplerate,self.update\u plot)
至self.after(采样器、self.update\u绘图)
tk.tk
不是有效的值。将在哪一行抛出错误?编辑:刚刚看到您的编辑请提供完整的回溯错误。Tkinter回调回溯中的异常(最近一次调用):文件“/Users/../anaconda/lib/python3.5/Tkinter/uuu init_uuuuuuuuuuuuuuuy.py”,调用返回self.func(*args)文件“/gui2.py”,第202行,在read\u data self.update\u plot()文件“/gui2.py”,第211行,在update\u plot func\u id=tk.tk.after(samplerate,self.update\u plot)文件“/Users/../anaconda/lib/python3.5/tkinter/\uu init\uuuuu.py”第592行的after self.tk.call('after',ms)AttributeError:'int'对象在您的问题中没有属性'tk',而不是注释lol.changefunc\u id=tk.after(samplerate,self.update\u plot)
至self.after(采样器、self.update\u绘图)
<代码>tk。tk不是有效值。
self.after(samplerate, self.update_plot)