'How to make Tkinter run in the background or make it handle keypress events outside of the Tkinter window?
The idea is that when the user presses the key combination Ctrl+P, Tkinter starts processing keyboard/mouse events regardless of which window is open.
Solution 1:[1]
You could use the keyboard module it will get the key even if you minimize the window.
Because inside Tkinter using a loop is not a good practice. This is why I use the root.after method to make a loop.
from tkinter import *
import keyboard
root = Tk()
def loop():
if keyboard.is_pressed(hotkey='ctrl+p'):
print('yes')
root.after(100,loop) # edited
loop()
root.mainloop()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
