Wondering how to bind an event to the left mouse button but not having to be hovered in the window/app/root. Basically, I want the event to happen where-ever my mouse pointer happens to be on my screen. Right now I can only figure out how to make the mouse button bindings work when the mouse is hovered on the window/app/root.
from tkinter import*
from tkinter import Tk, Label, StringVar
import random
import pyautogui
root = Tk()
root.configure(background='black')
root.attributes("-topmost", True)
root.overrideredirect(True)
root.geometry("100x100")
title_bar = Frame(root, bg='black')
title_bar.pack(side=TOP, fill=X)
tout = StringVar()
label = Label(root, textvariable=tout, font=('TkDefaultFont',
50), bg='black', fg='red')
label.pack()
def _quit():
root.quit()
root.destroy()
def move_app(event):
root.geometry(f'+{event.x_root}+{event.y_root}')
def gen_rand(event):
randvar = random.randint(0,99)
tout.set(randvar)
def clear_rand(event):
tout.set("")
myButton = Button(title_bar, text="X", font=('TkDefaultFont', 5),
bg='black', activebackground='red', fg='red', command=_quit)
myButton.pack(side=RIGHT)
root.bind('<Button-1>', gen_rand)
root.bind('<Button-3>', clear_rand)
root.bind("<B2-Motion>", move_app)
root.mainloop()