Search code examples
pythonpython-3.xtkinterttk

ttk combobox list values remain open after alt-tabbing


I have a class that inherits from ttk combobox. On a user doubleclick, I create this combobox and place it using .place() function

When I alt-tab and remove focus from my tkinter app, the list of combobox values remains displayed and can be interacted with, even though the rest of the gui does not have focus or visibility on my screen.

I am running windows 7.

class ComboBoxPopup(ttk.Combobox):

    def __init__(self, gui_parent, item_parent, values, **kw):
        ''' If relwidth is set, then width is ignored '''
        super().__init__(gui_parent, **kw)
        self.item_parent = item_parent
        self['values'] = values
        self['state'] = 'normal'
        self['exportselection'] = True
        self.focus_force()
        self.bind("<Escape>", lambda *ignore: self.destroy())
        self.bind("<Return>", lambda *ignore: self.commit_and_exit() )
        self.bind("<<ComboboxSelected>>", lambda *ignore: self.commit_and_exit())

EDIT:

I'm experimenting with this more, it seems like none of my events are bound to the dropdown of the combobox, just to the entryfield of the combobox. I think this is my problem.


Solution

  • None of the bindings I placed on my Combobox affected the drop-down listbox (I do not know the class name for that drop-down listbox).

    But once I bound handlers to the alt key presses for all tkinter widget classes, I was able to get the drop-down listbox under the program's control and kill the combobox widget popup.

            self.bind_all("<Alt_L>", self.configurationAbort)
            self.bind_all("<Alt_R>", self.configurationAbort)