[issue18686] Tkinter focus_get on menu causes crash

Jeffrey Goeders report at bugs.python.org
Thu Aug 8 18:55:42 CEST 2013


New submission from Jeffrey Goeders:

I am experiencing a crash when calling focus_get() when a Tk Menu has focus.  Here is sample code, just click the menu and it will crash.


import Tkinter as tk

class App(tk.Tk):
    def __init__(self, *args, **kw):
        tk.Tk.__init__(self, *args, **kw)
        
        self.entry = tk.Entry(self)
        self.entry.grid(padx=20, pady=20)
        self.entry.focus_set()
        self.entry.bind("<FocusOut>", self.entry_focus_lost)
        
        self.menubar = tk.Menu(self)
        self["menu"] = self.menubar
        
        self.menufile = tk.Menu(self.menubar, tearoff=False)
        self.menubar.add_cascade(menu=self.menufile, label="File")

    def entry_focus_lost(self, event):
        widget_with_focus = self.focus_get()


app = App()
app.mainloop()


Here is the error stack:
Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib64/python2.7/lib-tk/Tkinter.py", line 1410, in __call__
    return self.func(*args)
  File "/home/jgoeders/workspace/tester/test_menu_focus.py", line 19, in entry_focus_lost
    widget_with_focus = self.focus_get()
  File "/usr/lib64/python2.7/lib-tk/Tkinter.py", line 446, in focus_get
    return self._nametowidget(name)
  File "/usr/lib64/python2.7/lib-tk/Tkinter.py", line 1079, in nametowidget
    w = w.children[n]
KeyError: '#140030874747536'

----------
components: Tkinter
messages: 194693
nosy: jgoeders
priority: normal
severity: normal
status: open
title: Tkinter focus_get on menu causes crash
type: crash
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18686>
_______________________________________


More information about the Python-bugs-list mailing list