Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to delete label or button from tkinter window and then add it back?

Tags:

python

tkinter

Something like this:

from Tkinter import *

root = Tk()

but = Button(root, text = "button")
but.pack()
#When I try:
but.destroy()
but.pack()

I get an error:

TclError: bad window path name ".37111768"

like image 682
boxeus Avatar asked Mar 26 '12 20:03

boxeus


1 Answers

I have managed to get it working :) here is my work:

from Tkinter import *
def changebutton():
    but.destroy()
    secondbut=Button(root,text="changed")
    secondbut.pack()
if __name__=='__main__':
    root=Tk()
    global but
    but= Button(root,text="button",command=changebutton)
    but.pack()
    root.mainloop()
like image 155
IT Ninja Avatar answered Nov 07 '22 17:11

IT Ninja