[Tkinter-discuss] Exception protection to tk calls

Vasilis Vlachoudis Vasilis.Vlachoudis at cern.ch
Wed Mar 31 02:53:26 EDT 2021


Is there any recommendation which tkinter calls have to be protected with an exception handling
I occasionally receive traceback errors from my users on various calls
like: grab_current, grab_release, focus_get
most of the times I protect them with with a TclError handler catching exceptions
like_tkinter.TclError: bad window path name

Also which type of exception has to be protected, this is the first time I've got a KeyError
from a tkinter call, which normally should be innocent focus_get()"


Traceback:
Traceback (most recent call last):
  File "/usr/local/flair/tkFlair.py", line 1304, in __call__
    return self.func(*args)
  File "/usr/local/flair/InputExtra.py", line 1026, in focusOut
    self._focus = self.focus_get()
  File "/usr/lib/python3.8/tkinter/__init__.py", line 748, in focus_get
    return self._nametowidget(name)
  File "/usr/lib/python3.8/tkinter/__init__.py", line 1498, in nametowidget
    w = w.children[n]
KeyError: '__tk__messagebox'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/tkinter-discuss/attachments/20210331/d5dd6cb0/attachment.html>


More information about the Tkinter-discuss mailing list