I am trying to create a tkinter GUI which assigns a value to a variable when a button is pressed, then returns that value to be used in the rest of the code: 

```
from tkinter import *

def yes_command(ans):
    ans = 'yes' 
    window.destroy()
    return (ans)

def no_command(ans):
    ans = 'no'
    window.destroy()
    return (ans)

window = Tk()

yes_no_label = Label(window, text="Yes or no?")
yes_no_label.grid(row=0, column=1)

YESbutton = Button(window, text="Yes", fg='green', command = lambda :yes_command(ans))
YESbutton.grid(row=1, column=0)
NObutton = Button(window, text = 'No', fg = 'red', command= lambda :no_command(ans))
NObutton.grid(row=1, column=2)

window.mainloop()

print(ans)

```

In this, the GUI comes up and once a button is pressed, it does close. However, it does not output (as this is called outside of the function I know it would work if it printed). 

What further confuses me is that if I were to replace *return (ans)* with *print (ans)* it will print. Surely this just means it will not allow the value to leave the function? In which case, why? 

I would be grateful for any help, so thanks in advance.