Search code examples
pythontkinterattributeerror

Receiving an AttributeError: 'module' object has no attribute 'Intvar'


I don't know what is going on with my code. Whenever I run it, I receive an

AttributeError: 'module' object has no attribute 'Intvar' 

Here is my code:

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)

Also, if there are any other errors or discrepancies in my code, please let me know!

Thanks!


Solution

  • There's a typo in the following line:

    speed_intvar = Tkinter.Intvar()
    

    Intvar should be replaced with IntVar:

    speed_intvar = Tkinter.IntVar()
    #                         ^