1

I'm trying to create a transparent layer on top of the whole screen and display pointer position.
This is what I'm playing with:

#!/usr/bin/python3
import tkinter as tk
from tkinter import ttk

def hover( root, lb):
  x,y = root.winfo_pointerxy()
  lb['text'] = f"X={x}\nY={y}"
  lb.place( x=x, y=y)
  root.after( 200, hover, root, lb)
  
def createGlass():
  root = tk.Tk()
  root.wm_attributes( "-alpha", 0.0)
  root.wm_attributes( "-fullscreen", 1)
  #root.wm_overrideredirect( True)
  lb = ttk.Label( root)
  lb.place( x=0, y=0)
  hover( root, lb)
  root.mainloop()

if __name__ == '__main__': 
  createGlass()

Program works fine except that the layer is opaque and transparency is required. Platform is Linux 5.10 and tkInter is 8.6

user3435121
  • 633
  • 4
  • 13
  • You need to call `root.wait_visibility()` before `root.wm_attributes("-alpha", 0.0)`. However the window and the label are completely invisible, so you cannot see what you want. – acw1668 Mar 03 '23 at 02:20
  • @acw1668 same problem when I apply wait_visibility(). My desktop is KDE (plasma). I don't understand your remark about label visibility. Will alpha also affect foreground? Do yo know other ways? – user3435121 Mar 03 '23 at 14:39
  • 1
    It works in my kubuntu 22.10. Note that `alpha` setting applies to all widgets in the window as well. – acw1668 Mar 03 '23 at 15:22

0 Answers0