I have this program that guess the hexadecimal number of the colour pointed when "p" is pressed and it works, as you can see trying my code if you click out of the program area the program remains on top level and doesn't get covered by other programs, but the program loses the focus so in order to use the "p" function i have to click to the program and than press "p", do you know how to keep alway the program on focus even when i click out of the program area? Thanks a lot
from tkinter import *
import pyautogui
import pyperclip
import PIL.ImageGrab
from PIL import Image,ImageTk
from ctypes import windll
windll.shcore.SetProcessDpiAwareness(1)
b,x,y = "","",""
def cattura_colore(event):
global etichetta_valore
global b
global x
global y
try:
a = pyautogui.position()
a = str(a)
a = a.replace("Point","")
a = a.replace("(", "")
a = a.replace(")", "")
a = a.replace("x","")
a = a.replace("y", "")
a = a.replace("=", "")
b = a
x = a.split(",")[0]
y = a.split(",")[-1]
y = y.replace(" ","")
x,y = int(x),int(y)
print(x,y)
rgb = PIL.ImageGrab.grab().load()[x, y]
rgb = '#%02x%02x%02x' % (rgb)
rgb = rgb.upper()
print(rgb)
etichetta_valore["text"] = rgb
except(IndexError):
pass
except(NameError):
pass
window = Tk()
window.title("Valore esadecimale")
window.geometry("500x250")
window.resizable(width=False, height=False)
window.configure(bg="#292929")
window.attributes('-topmost', 1)
window.bind("<p>",cattura_colore)
etichetta_titolo_valore = Label(window, text="Valore:", font=("Ink Free", 20), bg="#292929", fg="white")
etichetta_titolo_valore.pack(pady=(20, 0))
etichetta_valore = Label(window, text="", font=("Ink Free", 20), bg="#292929", fg="white")
etichetta_valore.pack(pady=(10, 0))
window.mainloop()