import Tkinter as Tkt
import tkMessageBox, ttk

def ask_quit():
    if tkMessageBox.askokcancel('Quit', 'Realmente quiere cerrar todo?'):
        root.destroy()
        cond_exit.set(1)

root = Tkt.Tk()
root.protocol("WM_DELETE_WINDOW", ask_quit)         #This checks if when the operator click at the red X to close
                                                    #the window, was a counscious action or not

cond_exit = Tkt.IntVar()
cond_exit.set(0)

def new():
    root2 = Tkt.Toplevel()

    def ask_quit2():
        root2.destroy()
            
    root2.protocol("WM_DELETE_WINDOW", ask_quit2)

    L1 = ttk.Label(root2)
    L1.config(text = 'Window2')
    L1.pack()

    root2.mainloop()

L1 = ttk.Label(root)
L1.config(text = 'Window1')
L1.pack()

B1 = ttk.Button(root)
B1.config(text = 'New window', command = new)
B1.pack()
       
c = 0

while cond_exit.get() < 1:
    print c
    c += 1

    try:
        B1.update()
    except:
        pass
    

root.mainloop()
