[Tkinter-discuss] creating a conformation window that does multiple commands

Stewart Midwinter stewart.midwinter at gmail.com
Sun Mar 6 07:25:06 CET 2005


Jonathan:

I'm struggling a little bit to understand your note, but it seems you
want to do the following:
1. get confirmation from the user before quitting the app.  That's easy. 
2. in the confirmation, if the user chooses to not quit the app, you
want to run some other command. That's also easy.

My attached example accomplishes both of these objectives; maybe it'll
give you some ideas.

cheers
S

#quit-confirm.py
from Tkinter import *
from tkMessageBox import askyesno

root=Tk()

def editOptions():
    top=Toplevel()
    lab=Label(top, text="Do some stuff here")
    lab.pack(side='top')
    but1=Button(top, text="Close", command=top.destroy)
    but1.pack(side='top')
    
def confirm():
    ans=askyesno(title='Quit',message='Do you really want to quit?')
    if ans: sys.exit()
    #or we can also do the following:
    #if ans: root.destroy()
    else:
        editOptions()

mb=Menu(root)
root.configure(menu=mb)
mb.insert_cascade("end", label="File", underline=0)
mb.insert_cascade("end", label="Edit", underline=0, command=editOptions)
mb.insert_cascade("end", label="Quit", underline=0, command=confirm)

root.mainloop()




On Sat, 05 Mar 2005 18:36:14 +0000, Jonathan Stevens
<jstevens1984 at hotmail.com> wrote:
> Hello,
> I'm new to tkinter, so this might be a stupid question, but please bear with
> me. I have a gui made and when the user goes to file->quit a conformation
> window will pop up asking if they are sure that they want to quit, if "yes"
> then the program will quit. What I can not get it how to get the
> conformation window to be destroyed and the main program will quit with one
> command? Plus can this be done where, for another command instead of qiuting
> the program, i say go to another function but the pop up window does close?
> 
> Any advice will be much appreciated and I thank you all for helping me out
> 
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
> 


-- 
Stewart Midwinter
stewart at midwinter.ca
stewart.midwinter at gmail.com


More information about the Tkinter-discuss mailing list