Skip to content Skip to sidebar Skip to footer

Python Tkinter - Bind A "global" Key Shortcut Which Can Be Triggered From Outside The Window

I am thinking if there is any way to bind 'GLOBAL' key bindings to tk/ttk widgets for example: in this code: import tkinter as tk def output(lines = 'hehehehe'): print(lines)

Solution 1:

Not possible, you cannot access global key-strokes within tkinter, you will have to use some other external library like keyboard, should be fairly easy.

First install the library with pip install keyboard, then:

import tkinter as tk
import keyboard

....
keyboard.add_hotkey('ctrl+a', output, args=('From global keystroke',))
root.mainloop()

Post a Comment for "Python Tkinter - Bind A "global" Key Shortcut Which Can Be Triggered From Outside The Window"