title: Python how to always keep focus on window in Tkinter?
body: <p>I have this program that guess the hexadecimal number of the colour pointed when &quot;p&quot; 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 &quot;p&quot; function i have to click to the program and than press &quot;p&quot;, do you know how to keep alway the program on focus even when i click out of the program area? Thanks a lot</p>
  <pre><code>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 = &quot;&quot;,&quot;&quot;,&quot;&quot;
  def cattura_colore(event):
      global etichetta_valore
      global b
      global x
      global y
  
      try:
          a = pyautogui.position()
          a = str(a)
          a = a.replace(&quot;Point&quot;,&quot;&quot;)
          a = a.replace(&quot;(&quot;, &quot;&quot;)
          a = a.replace(&quot;)&quot;, &quot;&quot;)
          a = a.replace(&quot;x&quot;,&quot;&quot;)
          a = a.replace(&quot;y&quot;, &quot;&quot;)
          a = a.replace(&quot;=&quot;, &quot;&quot;)
          b = a
          x = a.split(&quot;,&quot;)[0]
          y = a.split(&quot;,&quot;)[-1]
          y = y.replace(&quot; &quot;,&quot;&quot;)
          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[&quot;text&quot;] = rgb
  
      except(IndexError):
          pass
      except(NameError):
          pass
  window = Tk()
  window.title(&quot;Valore esadecimale&quot;)
  window.geometry(&quot;500x250&quot;)
  window.resizable(width=False, height=False)
  window.configure(bg=&quot;#292929&quot;)
  window.attributes('-topmost', 1)
  window.bind(&quot;&lt;p&gt;&quot;,cattura_colore)
  etichetta_titolo_valore = Label(window, text=&quot;Valore:&quot;, font=(&quot;Ink Free&quot;, 20), bg=&quot;#292929&quot;, fg=&quot;white&quot;)
  etichetta_titolo_valore.pack(pady=(20, 0))
  etichetta_valore = Label(window, text=&quot;&quot;, font=(&quot;Ink Free&quot;, 20), bg=&quot;#292929&quot;, fg=&quot;white&quot;)
  etichetta_valore.pack(pady=(10, 0))
  window.mainloop()
  </code></pre>