Python 收到AttributeError:';模块';对象没有属性';Intvar';
我不知道我的代码是怎么回事。每当我运行它时,我都会收到Python 收到AttributeError:';模块';对象没有属性';Intvar';,python,tkinter,attributeerror,Python,Tkinter,Attributeerror,我不知道我的代码是怎么回事。每当我运行它时,我都会收到 AttributeError: 'module' object has no attribute 'Intvar' 这是我的密码: import Tkinter import math root = Tkinter.Tk() root.wm_title('Color-Shape Art Creation') speed_intvar = Tkinter.Intvar() speed_intvar.set(3) r=10 x=150
AttributeError: 'module' object has no attribute 'Intvar'
这是我的密码:
import Tkinter
import math
root = Tkinter.Tk()
root.wm_title('Color-Shape Art Creation')
speed_intvar = Tkinter.Intvar()
speed_intvar.set(3)
r=10
x=150
y=150
direction=0.5
canvas = Tkinter.Canvas(root, height=300, width=300, background='white')
canvas.grid(row=0, column=1, rowspan=3)
new_shape = canvas.create_oval(1,1,4,4,outline='white',fill='white')
red_intvar = Tkinter.IntVar()
blue_intvar = Tkinter.IntVar()
green_intvar = Tkinter.IntVar()
shapes = []
class ColorSlider(Tkinter.Scale):
def __init__(self, parent, myLabel, model_intvar, canvas):
def slider_changed(new_val):
tk_color_string = color(red_intvar, blue_intvar, green_intvar)
canvas.itemconfig(shapes[-1],fill=tk_color_string)
Tkinter.Scale.__init__(self, parent, orient=Tkinter.HORIZONTAL, from_=0, to=255,
variable = model_intvar, label=myLabel, command=slider_changed)
red_slider = ColorSlider(root, 'Red: ', red_intvar, canvas)
red_slider.grid(row=1, column=0, sticky=Tkinter.W)
此外,如果我的代码中有任何其他错误或差异,请让我知道
谢谢 下一行有一个输入错误:
speed_intvar = Tkinter.Intvar()
Intvar
应替换为Intvar
:
speed_intvar = Tkinter.IntVar()
# ^
'module'对象没有属性“Intvar”
,这意味着您在程序的第7行用Intvar
错误地键入了Intvar
。您应该做的是键入>>dir(Tkinter)
,并查看以“I”或“I”开头的名称的结果。在IDLE或其他IDE中,您可以改为键入>>Tkinter.
(注意“.”),然后等待出现名称完成列表,然后查看该列表。