0

i'm kinda new tkinter and i ran into a problem while using tkinter with python. I'm trying to get all of the buttons i have right now to take a number and add to it if the button is clicked or not, i ran into a wall and i have no idea how to fix it. Here's my code for reference.

from tkinter import *

class Application(Frame):
def __init__(self, master):
    super(Application, self).__init__(master)  
    self.grid()
    self.create_widgets()

def create_widgets(self):

    Label(self,
          text = "Enter information for services you need on your car"
          ).grid(row = 0, column = 0, columnspan = 2, sticky = W)

    #Oil Change
    Label(self,
          text = "Oil Change"
          ).grid(row = 2, column = 0, sticky = W)

    self.is_itchy = BooleanVar()
    Checkbutton(self,
                text = "$26.00",
                #error here
                variable = self.oil
                ).grid(row = 2, column = 1, sticky = W)


    #Lube Job
    Label(self,
        text = "Lube Job"
        ).grid(row = 3, column = 0, sticky = W)

    self.is_itchy = BooleanVar()
    Checkbutton(self,
                text = "$18.00",
                variable = self.is_itchy
                ).grid(row = 3, column = 1, sticky = W)

    #Radiator Flush
    Label(self,
          text = "Radiator Flush"
          ).grid(row = 4, column = 0, sticky = W)

    self.is_itchy = BooleanVar()
    Checkbutton(self,
                text = "$30.00",
                variable = self.is_itchy
                ).grid(row = 4, column = 1, sticky = W)

    #Transmission Flush
    Label(self,
          text = "Oil Change"
          ).grid(row = 5, column = 0, sticky = W)

    self.is_itchy = BooleanVar()
    Checkbutton(self,
                text = "$80.00",
                variable = self.is_itchy
                ).grid(row = 5, column = 1, sticky = W)

    #Inspection
    Label(self,
          text = "Inspection"
          ).grid(row = 6, column = 0, sticky = W)

    self.is_itchy = BooleanVar()
    Checkbutton(self,
                text = "$15.00",
                variable = self.is_itchy
                ).grid(row = 6, column = 1, sticky = W)

    #Muffler Replacement
    Label(self,
          text = "Muffler Replacement"
          ).grid(row = 7, column = 0, sticky = W)

    self.is_itchy = BooleanVar()
    Checkbutton(self,
                text = "$100.00",
                variable = self.is_itchy
                ).grid(row = 7, column = 1, sticky = W)

    #Tire Rotation
    Label(self,
          text = "Tire Rotation"
          ).grid(row = 8, column = 0, sticky = W)

    self.is_itchy = BooleanVar()
    Checkbutton(self,
                text = "$20.00",
                variable = self.is_itchy
                ).grid(row = 8, column = 1, sticky = W)

    #Buttons
    Button(self,
           text = "Click for total price",
           command = self.tell_story
           ).grid(row = 9, column = 0, sticky = W)

    self.story_txt = Text(self, width = 35, height = 5, wrap = WORD)
    self.story_txt.grid(row = 10, column = 0, columnspan = 3)

    Button(self,
           text = "Quit",
           command = quit
           ).grid(row = 9, column = 1, sticky = W)


def tell_story(self):
    """ Fill text box with new story based on user input. """
    # get values from the GUI
    if self.oil.get():
        print("Goofus")

    # create the story
    story = Price

    # display the story                                
    self.story_txt.delete(0.0, END)
    self.story_txt.insert(0.0, story)




root = Tk()
root.title("Joe's repair shop")
app = Application(root)
root.mainloop()

Here is the error i am getting

Traceback (most recent call last):
File "C:\Users\Kevin Holstein\Desktop\Classes\Python\Labs\Lab 10\Repair shop 
kholstein.py", line 127, in <module>
app = Application(root)
File "C:\Users\Kevin Holstein\Desktop\Classes\Python\Labs\Lab 10\Repair shop 
kholstein.py", line 8, in __init__
self.create_widgets()
File "C:\Users\Kevin Holstein\Desktop\Classes\Python\Labs\Lab 10\Repair shop 
kholstein.py", line 24, in create_widgets
variable = self.oil
AttributeError: 'Application' object has no attribute 'oil'
1
  • 1
    I'd also like to add that $18 for a "Lube Job" is quite cheap...( ͡º ͜ʖ ͡º) Commented Oct 25, 2017 at 15:16

1 Answer 1

2

On this line:

Checkbutton(self, text = "$26.00", variable = self.oil).grid(row = 2, column = 1, sticky = W)

You declare that the variable attribute of the Checkbutton widget should be equal to self.oil which you never give a value to, this throws an error as tkinter is trying to assign something which doesn't exist to this attribute.

Sign up to request clarification or add additional context in comments.

1 Comment

@Kevin Holstein You need to give self.oil a value like you do with self.is_itchy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.