Destroy function Tkinter
<p>In this program I am attempting to destroy all on screen widgets at the start of a new function and instantly re-create them on screen to replicate a new page appearing. I used the destroy function once already to "change pages" when clicking on the start button in the game menu which worked fine. </p>

<p>However when attempting to destroy all pages a second time when clicking on the canvas to the error:</p>

<blockquote>
  <p>_tkinter.TclError: bad window path name ".49314384"</p>
</blockquote>

<p>is presented.  </p>

<pre><code>from tkinter import *
    import tkinter

window = tkinter.Tk()                           #Here is where we set up the window and it's aesthetics,
window.title("BINARY-SUMZ!!!")                  #here we give the window a name,
window.geometry("1000x800")                     #here we give the window a size,
window.wm_iconbitmap('flower3.ico')             #and here we give the window an icon.

def Destroy():              #this function destroys any widgets on the current page.
    for widget in window.winfo_children():
        widget.destroy()

def StartButton():                                                                      #This function starts the game after being clicked on.

print ("Game started from beginning.")
Intro()                                                                  #This function starts the game after being clicked on.



def Menu():   #Creating a menu function
    SumsTitle = tkinter.Label(window, text="BINARY-SUMS!!!",                    #Here is where we create the title for the menu screen, we give it a name,               
                        fg = "light Green",                                 #a foreground (text) color
                        bg = "tomato",                                    #a backgorund color
                        font = "'Bauhaus 93 bold italic")
SumsTitle.pack()            #and the text is given a font.

StartButtonWid = tkinter.Button(window, text = "Start Learning!!!",
                                fg = "tomato",
                                command= (StartButton))
StartButtonWid.pack()             #Setting up the button for the start of the game.

TitleCanvas = tkinter.Canvas(window, bg = "light blue" ,
                             height = 1000,
                             width = 1000)
TitleCanvas.pack()

def Intro():
    Destroy()          #This function works fine
    SumsTitle = tkinter.Label(window, text="Welcome!!!",                    #Here is where we create the title for the menu screen, we give it a name,               
                        fg = "light green",                                 #a foreground (text) color
                        bg = "tomato",                                    #a backgorund color
                        height = 1,
                        width = 14,
                        font = "'Bauhaus 93 bold italic")
SumsTitle.pack()
Intro1 = tkinter.Label(window, text='Welcome to BINARY-SUMS!!! The fun, interactive binary learning game! in this game we will be learning about language based topics', 
                               font= "30")
Intro1.pack()
Intro2 = tkinter.Label(window, text='that will be vital to know in your AS computing or computer science exams. Please click the screen to continue.',
                               font= "30")
Intro2.pack()

IntroCanvas = tkinter.Canvas(window, bg = "light blue" ,
                             height = 1500,
                             width = 1000)

IntroCanvas.bind("&lt;Button-1&gt;",  Activ1())
IntroCanvas.pack()


def Activ1():
    Destroy()     #this function crashes.

if __name__ == "__main__":
    Menu()





tkinter.mainloop()
</code></pre>

<pre><code>IntroCanvas.bind("&lt;Button-1&gt;",  Activ1())
                                      ^^
IntroCanvas.pack()
</code></pre>

<p>You are getting the error in above lines.</p>

<p>Adding parentheses means, "<em>call</em> that function as soon as compiler reaches there". After <code>Activ1</code> gets called, it calls <code>Destroy()</code> which destroys <code>IntroCanvas</code> then you are trying to <code>pack</code> destroyed widget. Hence you are getting that error.</p>

<p>As a debug note, if you see an error message like this one, most of the times it is because you are trying to do some action on <em>destroyed</em> widget/object so you should look for your destroying calls. </p>

<p>For solution,<br>
You should remove parenthesis and add an argument to <code>Activ1</code>. </p>

<pre><code>IntroCanvas.bind("&lt;Button-1&gt;",  Activ1)

def Activ1(event): 
</code></pre>

python tkinter destroy tkinter-canvas