Twhite1195
Twhite1195

Reputation: 351

tkinter Toplevel objext is not callable

good evening guys, I've been having trouble lately with tkinter windows. I have a program in which the users can "buy" stuff from stores, after adding the wanted products to the cart, a button takes them to the "final" review of the order, in which they can remove items they don't want, the problem is, I need to destroy that window, display the information window saying that "the item you didn't wanted has been removed from your cart", and run the "final preview" again (with the new data, AKA without the undesirable item). Problem is, after destroying the window, an error appears saying:

TypeError: 'Toplevel' object is not callable

The structure of my code is something like this:

def reviewwindow(*previous window*,cartlist):
    previuswindow.destroy()
    reviewwindow=Toplevel(gui)
    reviewwindow.title("cart review")
    reviewwindow.geometry("450x450")
    #code about the stuff I need to do#
    botonb= Button(reviewwindow, text = "Delete items",command=lambda:       deleteitems(reviewwindow,*previous window*,cartlist,delete), width=7)
botonb.grid(row=8,column=1)

def deleteitems(reviewwindow,*previous window*,cartlist,delete):
   reviewwindow.destroy()
   deleteitems=Toplevel(gui)
   deleteitems.title("delete")
   deleteitems.geometry("300x300")

#code##code#
boton= Button(deleteitems, text = "go back",command=lambda:reviewwindow(*previous window*,new_cartlist), width=9)
boton.grid(row=2,column=1)

I don't know if I made my problem clear enough, I you need more explanations or something I'll gladly provide more.

Upvotes: 0

Views: 2037

Answers (1)

TigerhawkT3
TigerhawkT3

Reputation: 49320

The problem is that you have a function called reviewwindow, but then you assign Toplevel(gui) to reviewwindow. Same goes for deleteitems. When you call those functions, the program tries to call a Toplevel object, and those aren't callable. Choose unique names for every unique value.

Upvotes: 1

Related Questions