Python Forum
Show all available bindings for given widget - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: Code sharing (https://python-forum.io/forum-5.html)
+--- Thread: Show all available bindings for given widget (/thread-1119.html)



Show all available bindings for given widget - Larz60+ - Dec-05-2016

I needed to know available bindings for a ttk Notebook widget, and had a hard time finding them
This class will show available bindings for any widget:
class WidgetBindings:
    def __init__(self, wobject):
        instance = wobject()
        self.process(instance)
        instance.destroy()

    @staticmethod
    def process(instance):
        bindings = set()
        for bindtag in instance.bindtags():
            bindings |= set(instance.bind_class(bindtag))
        for item in bindings:
            print(item)


if __name__ == '__main__':
    import tkinter.ttk
    print('ttk.Notebook bindings')
    WidgetBindings(tkinter.ttk.Notebook)
Output:
ttk.Notebook bindings <Destroy> <Control-Shift-Key-Tab> <Key-Right> <Control-Key-Tab> <Button-1> <Key-Left> <Destroy> <Control-Shift-Key-Tab> <Key-Right> <Control-Key-Tab> <Button-1> <Key-Left> <Destroy> <Key-F10> <<PrevWindow>> <KeyRelease-F10> <KeyRelease-Alt_L> <Key-Alt_R> <Button-1> <Key-Left> <Alt-Key> <Alt-KeyRelease> <<NextWindow>> <KeyRelease-Alt_R> <Control-Shift-Key-Tab> <Key-Right> <Control-Key-Tab> <Key-Alt_L>

what happened to the output??
Edit admin:
Fixed output.