Tkinter keybinding for Control-Shift-Tab

点点圈 提交于 2019-12-22 12:37:47

问题


What's the key-binding for Control-Shift-Tab? I've tried lots of things and nothing seems to work. I'm already aware of tkinter.ttk.Notebook.enable_traversal.

If you know of a handler for tabs being activated, that would suffice, too.


回答1:


The general format for representing an event is: <[event modifier(s)-]...event type [-event detail]>. For key-binding Ctrl+Shift+Tab the format would be: 'Control-Shift-KeyPress-Tab'. In this case the event modifiers would be: Control- Shift-, the event type: Keypress, and the event detail: -Tab

The following code (in python 2.7.6) should make it clear:

from Tkinter import *

def key(event=None):
    print 'You pressed Ctrl+Shift+Tab'

root = Tk()

frame = Frame(root, width=100, height=100)
frame.focus_set()
frame.bind('<Control-Shift-KeyPress-Tab>', key)
frame.pack()

root.mainloop()

EDIT: The above works well for Windows and Mac. For Linux, use

'<Control-ISO_Left_Tab>'.


来源:https://stackoverflow.com/questions/23377819/tkinter-keybinding-for-control-shift-tab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!