Created
October 17, 2022 21:47
-
-
Save tsbertalan/666cf32a12f7f1e60ddd0e20cf4746a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import tkinter as tk | |
from sys import platform | |
# Draw a circle around the pointer. Use tkinter to make circle without window. | |
root = tk.Tk() | |
#root.config(bg='') | |
#root.overrideredirect(True) | |
#root.wm_attributes("-topmost", True) | |
#root.wm_attributes("-transparentcolor", "white") | |
#root.wm_attributes("-alpha", 0.5) | |
# https://stackoverflow.com/questions/19080499/transparent-background-in-a-tkinter-window | |
if platform == "linux" or platform == "linux2": | |
root.overrideredirect(True) | |
root.wait_visibility(root) | |
root.wm_attributes("-alpha", 0.5) | |
elif platform == "darwin": | |
root.overrideredirect(True) | |
# Make the root window always on top | |
root.wm_attributes("-topmost", True) | |
# Turn off the window shadow | |
root.wm_attributes("-transparent", True) | |
# Set the root window background color to a transparent color | |
root.config(bg='systemTransparent') | |
root.geometry("+300+300") | |
# Store the PhotoImage to prevent early garbage collection | |
root.image = tk.PhotoImage(file="photoshop-icon.gif") | |
# Display the image on a label | |
label = tk.Label(root, image=root.image) | |
# Set the label background color to a transparent color | |
label.config(bg='systemTransparent') | |
label.pack() | |
elif platform == "win32": | |
root.image = tk.PhotoImage(file='startup.gif') | |
label = tk.Label(root, image=root.image, bg='white') | |
root.overrideredirect(True) | |
root.geometry("+250+250") | |
root.lift() | |
root.wm_attributes("-topmost", True) | |
root.wm_attributes("-disabled", True) | |
root.wm_attributes("-transparentcolor", "white") | |
label.pack() | |
# Make the canvas fill the monitor. | |
canvas = tk.Canvas(root, width=root.winfo_screenwidth(), height=root.winfo_screenheight(), bg="black") | |
#def draw_circle(event): | |
# x = event.x | |
# y = event.y | |
# r = 100 | |
# # Make a semitransparent circle. | |
# canvas.create_oval(x-r, y-r, x+r, y+r, fill='red', outline='red', width=10, stipple='gray50') | |
# #canvas.create_oval(x-r, y-r, x+r, y+r, fill="red", outline="red") | |
# canvas.pack(fill="both", expand=True) | |
#canvas.bind("<Motion>", draw_circle) | |
# The above makes a circle on every mouse move, but they accumulate and don't go away. | |
# The following makes a circle on every mouse move, but it replaces the previous circle. | |
def draw_circle(event): | |
canvas.delete("all") | |
x = event.x | |
y = event.y | |
r = 100 | |
# Make a semitransparent circle. | |
canvas.create_oval(x-r, y-r, x+r, y+r, fill='white', outline='white', width=10, stipple='gray50') | |
#canvas.create_oval(x-r, y-r, x+r, y+r, fill="red", outline="red") | |
canvas.pack(fill="both", expand=True) | |
canvas.bind("<Motion>", draw_circle) | |
# Call the draw_circle function even before the mouse is moved. | |
# For this, we need to generate an event with the current mouse location. | |
ev = tk.Event() | |
ev.x = root.winfo_pointerx() | |
ev.y = root.winfo_pointery() | |
draw_circle(ev) | |
# On click, exit. | |
def exit(event): | |
root.destroy() | |
canvas.bind("<Button-1>", exit) | |
# Don't know what this does. | |
canvas.pack(fill="both", expand=True) | |
root.mainloop() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment