Hung Truong Hung Truong - 5 months ago 13
Python Question

Tkinter : Issue with creating keyboard shortcuts

I'm having problem with making keyboard shortcuts for my program. I couldn't seem to get

root.bind("<Control-Shift-s>",function)
to work, but
root.bind("<Control-s>",function)
works perfectly. Here's the example code:

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()

Answer

Change:

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

To:

root.bind("<Control-Shift_L><S>",function)

(Reference)

EDIT:

Additional note:

To get your actual code working, you need to modify:

def function():
    print("This is a function")

To:

def function(event):
    print("This is a function")