I have a simple Tkinter window, started from an IPython console (so mainloop() is not called, in case that's relevant)
When I press Ctrl+C in the console, nothing happens... until the Tkinter window does something, at which point it catches the KeyboardInterrupt and raises an error.
The question is: how do I catch that KeyboardInterrupt? It seems that no matter where I put a try: block, it is too late already...
Here's an example:
class App(object):
def __init__(self,):
self.root = tk.Tk()
self.root.bind('<FocusIn>', self.focus_in)
def focus_in(self, event):
print 'I got focus'
in the IPython console:
app = App()
Now press Ctrl+C in the console. Then click on the App window... and bang:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/lib-tk/Tkinter.py", line 1481, in __call__
def __call__(self, *args):
KeyboardInterrupt
Adding a 'try/except KeyboardInterrupt' block inside focus_in does not help.
So? Is this a bug? Should TKinter even see that interrupt? Can I disable SIGINT while IPython is idle? (Naturally I still want it when it is running some code...)