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