TypeError in Application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smiths7
    New Member
    • May 2010
    • 1

    TypeError in Application

    Hey guys,

    I'm new to python and tkinter and am building a quote module thats interface is up and running but the button definitions arent working and i get an error when my "QUOTE" button is pressed. Please help.

    Code:
    ERROR:
    Traceback (most recent call last):
    TypeError: unsupported operand type(s) for +: 'type' and 'str'
    Code:
    CODE:
    from Tkinter import *
    import Pmw
    
    ##### ROOT WINDOW SET UP #####
    root = Tk()
    root.geometry("320x480+200+200")
    root.title("procedure module")
    Pmw.initialise(root)
    
    
    ##### ENTRY WIDGETS ####
    GName_Entry=StringVar()
    GName_Entry=Pmw.EntryField(root, validate = {'validator' : 'alphabetic', 'max' : 10}).grid(row=4, column=1)
    SName_Entry=StringVar()
    SName_Entry=Pmw.EntryField(root, validate = {'validator' : 'alphabetic', 'max' : 10}).grid(row=4, column=2)
    Email_Entry=StringVar()
    Email_Entry=Pmw.EntryField(root, validate = {'max' : 30}).grid(row=6, column=1)
    BalloonHours_Entry=IntVar()
    BalloonHours_Entry=Pmw.EntryField(root, validate = {'validator' : 'numeric', 'max' : 48}).grid(row=6, column=2)
    PeopleCharge_Entry=IntVar()
    PeopleCharge_Entry=Pmw.EntryField(root, validate = {'validator' : 'numeric', 'max' : 20}).grid(row=8, column=1)
    LunchRequest_Entry=IntVar()
    LunchRequest_Entry=Pmw.EntryField(root, validate = {'validator' : 'numeric', 'max' : 20}).grid(row=8, column=2)
    SouvenirRequest_Entry=IntVar()
    SouvenirRequest_Entry=Pmw.EntryField(root, validate = {'validator' : 'numeric', 'max' :20}).grid(row=10,column=1)
    SubTotal_Entry=IntVar()
    SubTotal_Entry=Pmw.EntryField(root).grid(row=13, column=1)
    GST_Entry=IntVar()
    GST_Entry=Pmw.EntryField(root).grid(row=13, column=2)
    Total_Entry=IntVar()
    Total_Entry=Pmw.EntryField(root).grid(row=15, column=2)
    
    #### BUTTON FUNCTIONS ####
    
    def calculation():
        SubTotal_Entry.delete(0,END)
        STResult=BalloonHours_Entry.getvalue()*100+PeopleCharge_Entry.getvalue()*70+LunchRequest_Entry.getvalue()*50+SouvenirRequest_Entry.getvalue()*20
        SubTotal_Entry.insert(END,STResult)
        GST_Entry.delete(0,END)
        GSTResult=SubTotal_Entry.getvalue()*0.10
        GST_Entry.insert(END,GSTResult)
        Total_Entry.delete(0,END)
        TResult=SubTotal_Entry.getvalue()+GST_Entry.getvalue()
    # defines quote button and allows calculations to be completed
    
    def cleardef():
        GName_Entry.delete(0,END)
        SName_Entry.delete(0,END)
        Email_Entry.delete(0,END)
        BalloonHours_Entry.delete(0,END)
        PeopleCharge_Entry.delete(0,END)
        LunchRequest_Entry.delete(0,END)
        SouvenirRequest_Entry.delete(0,END)
        SubTotal_Entry.delete(0,END)
        GST_Entry.delete(0,END)
        Total_Entry.delete(0,END)
    # defines clear button and allows entry boxes to be cleared from any input
    
    #### BUTTONS ####
    #Quote button
    QB=Button(root,text="QUOTE", width=10, command=calculation).grid(row=10, column=2)
    
    #Clear button
    CB=Button(root,text="CLEAR", width=10, command=cleardef).grid(row=18, column=1)
    
    ##### EXECUTE PROGRAM #####
    root.mainloop()
    Please help! Thank you very much!
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Originally posted by smiths7
    Hey guys,

    I'm new to python and tkinter and am building a quote module thats interface is up and running but the button definitions arent working and i get an error when my "QUOTE" button is pressed. Please help.

    Code:
    ERROR:
    Traceback (most recent call last):
    TypeError: unsupported operand type(s) for +: 'type' and 'str'
    Code:
    CODE:
    from Tkinter import *
    import Pmw
    
    ##### ROOT WINDOW SET UP #####
    root = Tk()
    root.geometry("320x480+200+200")
    root.title("procedure module")
    Pmw.initialise(root)
    
    
    ##### ENTRY WIDGETS ####
    GName_Entry=StringVar()
    GName_Entry=Pmw.EntryField(root, validate = {'validator' : 'alphabetic', 'max' : 10}).grid(row=4, column=1)
    SName_Entry=StringVar()
    SName_Entry=Pmw.EntryField(root, validate = {'validator' : 'alphabetic', 'max' : 10}).grid(row=4, column=2)
    Email_Entry=StringVar()
    Email_Entry=Pmw.EntryField(root, validate = {'max' : 30}).grid(row=6, column=1)
    BalloonHours_Entry=IntVar()
    BalloonHours_Entry=Pmw.EntryField(root, validate = {'validator' : 'numeric', 'max' : 48}).grid(row=6, column=2)
    PeopleCharge_Entry=IntVar()
    PeopleCharge_Entry=Pmw.EntryField(root, validate = {'validator' : 'numeric', 'max' : 20}).grid(row=8, column=1)
    LunchRequest_Entry=IntVar()
    LunchRequest_Entry=Pmw.EntryField(root, validate = {'validator' : 'numeric', 'max' : 20}).grid(row=8, column=2)
    SouvenirRequest_Entry=IntVar()
    SouvenirRequest_Entry=Pmw.EntryField(root, validate = {'validator' : 'numeric', 'max' :20}).grid(row=10,column=1)
    SubTotal_Entry=IntVar()
    SubTotal_Entry=Pmw.EntryField(root).grid(row=13, column=1)
    GST_Entry=IntVar()
    GST_Entry=Pmw.EntryField(root).grid(row=13, column=2)
    Total_Entry=IntVar()
    Total_Entry=Pmw.EntryField(root).grid(row=15, column=2)
    
    #### BUTTON FUNCTIONS ####
    
    def calculation():
        SubTotal_Entry.delete(0,END)
        STResult=BalloonHours_Entry.getvalue()*100+PeopleCharge_Entry.getvalue()*70+LunchRequest_Entry.getvalue()*50+SouvenirRequest_Entry.getvalue()*20
        SubTotal_Entry.insert(END,STResult)
        GST_Entry.delete(0,END)
        GSTResult=SubTotal_Entry.getvalue()*0.10
        GST_Entry.insert(END,GSTResult)
        Total_Entry.delete(0,END)
        TResult=SubTotal_Entry.getvalue()+GST_Entry.getvalue()
    # defines quote button and allows calculations to be completed
    
    def cleardef():
        GName_Entry.delete(0,END)
        SName_Entry.delete(0,END)
        Email_Entry.delete(0,END)
        BalloonHours_Entry.delete(0,END)
        PeopleCharge_Entry.delete(0,END)
        LunchRequest_Entry.delete(0,END)
        SouvenirRequest_Entry.delete(0,END)
        SubTotal_Entry.delete(0,END)
        GST_Entry.delete(0,END)
        Total_Entry.delete(0,END)
    # defines clear button and allows entry boxes to be cleared from any input
    
    #### BUTTONS ####
    #Quote button
    QB=Button(root,text="QUOTE", width=10, command=calculation).grid(row=10, column=2)
    
    #Clear button
    CB=Button(root,text="CLEAR", width=10, command=cleardef).grid(row=18, column=1)
    
    ##### EXECUTE PROGRAM #####
    root.mainloop()
    Please help! Thank you very much!
    What error message did you receive? Often that can help pinpoint the problem.

    Comment

    • dwblas
      Recognized Expert Contributor
      • May 2008
      • 626

      #3
      TypeError: unsupported operand type(s) for +: 'type' and 'str'
      You are trying to add two different types together. Since we don't have a line number of the error, the most that can be said is to check that you are using the same type for variables on any line that has a "+".

      Comment

      • bvdet
        Recognized Expert Specialist
        • Oct 2006
        • 2851

        #4
        dwblas has a better eye than I do. I see the error message now, and apparently it comes from the function calculation(). Here's something I don't understand. What is the purpose of this code:
        Code:
        LunchRequest_Entry=IntVar()
        LunchRequest_Entry=Pmw.EntryField(root, validate = {'validator' : 'numeric', 'max' : 20}).grid(row=8, column=2)
        Several times you create an IntVar and then you immediately reassign the variable to None (the grid() method returns None). Straighten that out first, and your other problem may go away or may become obvious. I am not familiar with Pmw, so there may be something going on I am not aware of.

        Please post back on how it goes for you.

        BV

        Comment

        Working...