Skip to content

Instantly share code, notes, and snippets.

@Curtis-64
Last active September 29, 2023 18:21
Show Gist options
  • Save Curtis-64/aa0b7f0cf8b67298798150818dc20497 to your computer and use it in GitHub Desktop.
Save Curtis-64/aa0b7f0cf8b67298798150818dc20497 to your computer and use it in GitHub Desktop.
Python Notebook Grid and Locator Code
'Grid & Locator Code by Curtis White / GPT-4 AD
'Not well tested-- run at own risk. In early tests, it can prevent interaction with system. It works perfectly now, on my system.
'but if you see tha use task manager to kill the kernerl process not from the task manaager but from the task changer layout.
!pip install pynput
import tkinter as tk
from pynput import mouse
def on_move(x, y):
"""Update mouse coordinates when moved."""
canvas.coords(mouse_text, x, y-30)
canvas.itemconfig(mouse_text, text=f"X: {x}, Y: {y}")
def draw_grid():
for line in lines:
canvas.delete(line)
for text in texts:
canvas.delete(text)
lines.clear()
texts.clear()
if grid_visible:
for i in range(0, screen_width, 75):
lines.append(canvas.create_line(i, 0, i, screen_height, fill="red"))
for j in range(0, screen_height, 75):
texts.append(canvas.create_text(i+5, j, text=f"{i},{j}", fill="white", font=('Arial', 10)))
for i in range(0, screen_height, 75):
lines.append(canvas.create_line(0, i, screen_width, i, fill="red"))
WinSet_TransColor('gray') # Make overlay interactive
else:
WinSet_TransColor('transparent') # Make overlay non-interactive
def WinSet_TransColor(color):
"""Set the transparency color for the window."""
root.attributes('-transparentcolor', color)
def toggle_grid():
global grid_visible
grid_visible = not grid_visible
draw_grid()
def close_overlay():
root.quit()
root.destroy()
mouse_listener.stop()
root = tk.Tk()
root.attributes('-fullscreen', True, '-alpha', 0.3, '-topmost', True)
root.overrideredirect(True)
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
canvas = tk.Canvas(root, bg='gray', bd=0, highlightthickness=0)
canvas.pack(fill=tk.BOTH, expand=tk.TRUE)
lines = []
texts = []
grid_visible = True
draw_grid()
mouse_text = canvas.create_text(100, 100, text="", fill="white", font=('Arial', 20))
mouse_listener = mouse.Listener(on_move=on_move)
mouse_listener.start()
close_btn = tk.Button(root, text="Close Overlay", command=close_overlay, bg='white')
close_btn.place(x=screen_width-150, y=10)
toggle_btn = tk.Button(root, text="Toggle Grid", command=toggle_grid, bg='white')
toggle_btn.place(x=screen_width-300, y=10)
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment