I'm just starting out with Tkinter programming (using Programming
Python as a reference), and I couldn't find the answer to this
anywhere...
How do you catch general exceptions in a Tkinter program. If you run
the below and click the "Exception" or "Callback Exception" buttons
you see a traceback on stderr under unix, and nothing at all under
windows (if run as a pyw).
How so you catch those exceptions so that they can pop up in a dialog?
There doesn't seem to be a hook. I was imagining that there would be a
global error handler I could hook / override?
from Tkinter import *
class AppDemo(Frame):
"""A sample tk app"""
def __init__(self, parent=None):
Frame.__init__( self, parent)
self.pack(expan d=YES, fill=BOTH)
self.make_tool_ bar()
self.master.tit le("A Title")
self.bang = 0
self.process()
def process(self):
self.after(1000 , self.process)
if self.bang:
self.bang = 0
raise ValueError("Cal lback Exception")
def make_tool_bar(s elf):
self.toolbar = Frame(self, cursor='hand2', relief=SUNKEN, bd=2)
self.toolbar.pa ck(side=BOTTOM, fill=X)
Button(self.too lbar, text='Exception ', command=self.ma ke_exception).p ack(side=TOP, fill=X)
Button(self.too lbar, text='Callback Exception', command=self.ma ke_callback_exc eption).pack(si de=TOP, fill=X)
Button(self.too lbar, text='Quit', command=self.qu it).pack(side=T OP, fill=X)
def make_exception( self):
raise ValueError("Exc eption")
def make_callback_e xception(self):
self.bang = 1
if __name__ == "__main__":
AppDemo().mainl oop()
--
Nick Craig-Wood <ni**@craig-wood.com-- http://www.craig-wood.com/nick