hey guys im trying to work this out for a school assignment, i cant get the destroy function to work whith the button i created, heres mycode see if you can look at it and tell me whas wrong

import Tkinter as tk

root = tk.Tk()
root.title('background image')

def qwerty():
    self.destroy(button2)

#def qwerty():
image1 = tk.PhotoImage(file="Black.gif")
w = image1.width()
h = image1.height()
panel1.image = image1
root.geometry("%dx%d+0+0" % (w, h))

panel1 = tk.Label(root, image=image1)
panel1.pack(side='top', fill='both', expand='yes')

self.button2 = tk.Button(panel1, text='Click here to continue', command = qwerty)
self.button2.pack(side='bottom')




root.mainloop()

The code you posted wouldn't even compile, let alone run.

Please be specific in the problem you are having.

I think the following is close to what you wanted, but it uses global variables which have their own problems:

import Tkinter as tk

root = tk.Tk()
root.title('background image')

def qwerty():
    button2.destroy()
    
#def qwerty():
image1 = tk.PhotoImage(file="Black.gif")

w = image1.width()
h = image1.height()
#panel1.image = image1
root.geometry("%dx%d+0+0" % (w, h))

panel1 = tk.Label(root, image=image1)
panel1.pack(side='top', fill='both', expand='yes')

button2 = tk.Button(panel1, text='Click here to continue', command = qwerty)
button2.pack(side='bottom')

root.mainloop()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.