Skip to main content
 首页 » 编程设计

python之Tkinter : Issue with creating keyboard shortcuts

2025年04月02日12Terrylee

我在为我的程序创建键盘快捷键时遇到问题。我似乎无法获得 root.bind("<Control-Shift-s>",function)上类,但是root.bind("<Control-s>",function)工作完美。这是示例代码:

from tkinter import * 
 
root = Tk() 
def function(): 
    print("This is a function") 
 
root.bind("<Control-Shift-s>",function) # Doesn't work 
root.bind("<Control-s>",function) # Works perfectly 
 
root.mainloop() 

请您参考如下方法:

改变:

root.bind("<Control-Shift-s>",function) # Doesn't work 

其中之一:

  1. root.bind("< 控制 - Shift_L >< S> ",function)
  2. root.bind("< 控制 - Shift_R >< S >",function)
  3. root.bind("< 控制 - Shift - S >",function)

( Reference )