Best practice approach for trapping Tkinter exceptions

python at bdurham.com python at bdurham.com
Sat Nov 6 12:04:56 CET 2010


What is the best practice approach for trapping Tkinter
exceptions?

Example: When using the Text widget with undo=True, attempting an
edit_undo or edit_redo raises a Tkinter exception when there are
no actions to undo or redo.

It doesn't look like there's a Tkinter specific exception being
raised - only a general exception.

Is there a better way to trap Tkinter exceptions than wrapping
certain Tkinter commands like the following:

try:
    widget_with_focus.edit_undo()
except Exception as e:
     pass

If I print the exception that I trapped, all I get is the name of
the Tkinter method I tried to execute, eg. edit_undo.

For bonus points: Is there a way to query a Tkinter Text widget
to determine if there are undo or redo actions available to
apply?

Malcolm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101106/b7036e5c/attachment.html>


More information about the Python-list mailing list