tkinter - python 3 - clear the screen
<p>I went through the topics here at stack overflow, but could not understand anything. (yes, I've seen that the answer has been answered, but really couldnt understand.)</p>

<p>So, here's the thing.
I'm building small application that will pair couples from a group for a tournament we're having. I successfully built the algorithm that pair the players, and I've decided to make this a bit more approachable to everyone and started looking at ktinker.</p>

<p>I've managed to get my application to show something like this:</p>

<pre><code>Title
info
info
info
info
info
Button
</code></pre>

<p>The button suppose to re-run the whole thing (next round) and it works. I've managed to get it with the appropriate title, and even added a new button at the end of the screen. the only problem I'm having is that I want to get rid of all the text above. destroy it and just draw on a new page.</p>

<p>Now, the code:</p>

<pre><code>from tkinter import *

root = Tk()

root.title("Tournament")
root.geomerty("50x180")

app = Frame(root)
app.grid()

run_application() # my pairings 
#inside the code i'm pairing the players and then:
for players in player_paired:
    label=Label(app, text=players[0]+' vs. '+players[1] # its a tuple
    label.grid()
button=Button(app,text="Next Round", command=run_application)
button.grid()

#end of run_application

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

<p>So, I've tried adding to the beginning of my "run_application" the next rows:</p>

<pre><code>app.destroy()
app = Frame(root)
app.grid()
</code></pre>

<p>and got "UnboundLocalError: local variable 'app' referenced before assignment"</p>

<p>Would anyone help? i can't figure this out.
(If able to write example, it would help a lot)</p>

<p>Ofek.</p>

<p>In my experience, I found it easier to delete the elements. Here is something you can do. I don't honestly have much time, so I will use examples from my code, instead of editing your code. </p>

<p>So for your labels you could do this.</p>

<pre><code>labels = []
for players in player_paired:
    label=Label(app, text=players[0]+' vs. '+players[1] # its a tuple
    label.grid()
    labels.append(label)
</code></pre>

<p>Then to remove the text have a method that does something like this.</p>

<pre><code>for label in labels:
        label.destroy()
</code></pre>

<p>And then go back to the start after that.</p>

python python-3.x tkinter