Binding Multiple Keys To A Function In Tkinter Python
Say if i wish to bind my space bar and the key 'w' to any random function in my code, how would i do this? Should i be using if 'w' and if '' then perform or can you bind multiple
Solution 1:
In tkinter
you can put string with all keys "<space>w"
and you can do: press space, (release space or not), press w
and it will run function.
import tkinter as tk
deftest(event):
print('test')
root = tk.Tk()
root.bind('<space>w', test)
root.mainloop()
Solution 2:
By just adding the and, I was able to bind this Text entry box to both the tab and enter keys. I suppose if you wanted each key to run a different function, you could.
Text.bind("<Tab>", AddText) and Text.bind("<Return>", AddText)
Post a Comment for "Binding Multiple Keys To A Function In Tkinter Python"