close window in Tkinter message box

Posted by rejinacm on Stack Overflow See other posts from Stack Overflow or by rejinacm
Published on 2009-07-20T09:18:40Z Indexed on 2010/03/19 2:01 UTC
Read the original article Hit count: 588

Filed under:
|
|

Hello,

link text

How to handle the "End Now" error in the below code:

import Tkinter
from Tkconstants import *
import tkMessageBox

tk = Tkinter.Tk()

class MyApp:

    def __init__(self,parent):

        self.myparent = parent

        self.frame = Tkinter.Frame(tk,relief=RIDGE,borderwidth=2)
        self.frame.pack()

        self.message = Tkinter.Message(tk,text="Symbol Disolay")

        label=Tkinter.Label(self.frame,text="Is Symbol Displayed")
        label.pack()

        self.button1=Tkinter.Button(self.frame,text="YES")
        self.button1.pack(side=BOTTOM)
        self.button1.bind("<Button-1>", self.button1Click)

        self.button2=Tkinter.Button(self.frame,text="NO")
        self.button2.pack()
        self.button2.bind("<Button-1>", self.button2Click)

        self.myparent.protocol("WM_DELETE_WINDOW", self.handler)


    def button1Click(self, event):
            print "pressed yes"

    def button2Click(self, event):
            print "pressed no"


    def handler(self):
        if tkMessageBox.askokcancel("Quit?", "Are you sure you want to quit?"):
            self.myparent.quit()


myapp = MyApp(tk)
tk.mainloop()

© Stack Overflow or respective owner

Related posts about python

Related posts about closewindow