#!/usr/bin/env python3
from tkinter import *
from tkinter import ttk

# Thanks to https://www.google.com/search?q=tkinter+onclick+event+for+button+press&rlz=1C5OZZY_en&oq=tkinter+onclick+event+for+button+press&gs_lcrp=EgZjaHJvbWUyBggAEEUYOTIHCAEQIRigATIHCAIQIRigATIHCAMQIRiPAtIBCTE3MDY1ajBqNKgCALACAQ&sourceid=chrome&source=chrome.ob&ie=UTF-8
# 1. Define the callback function
def handle_click():
    print("Button was clicked!")


# 1. Define a function that accepts the event object
def handle_right_or_left_click(event):
    # event.widget gives you the specific button that was clicked
    print(f"Right Clicked on {event.widget['text']} at X: {event.x}, Y: {event.y}")


# 1. Define a function that accepts the event object
def handle_left_or_right_click(event):
    # event.widget gives you the specific button that was clicked
    print(f"Clicked on {event.widget['text']} at X: {event.x}, Y: {event.y}")


root = Tk()
ttk.Button(root, text="Left or right click me") #, command=handle_click).grid()

#  CORRECT: Added () to instantiate the Label object
my_label = ttk.Label(root, text="Left or right click of me") 

# This works because my_label is now a valid instance
my_label.pack() 


# 2. Bind specific mouse sequences
my_label.bind("<Button-1>", handle_left_or_right_click)  # Left Mouse Click
my_label.bind("<Button-2>", handle_right_or_left_click)  # Right Mouse Click
my_label.bind("<Button-3>", handle_right_or_left_click)  # Right Mouse Click

root.mainloop()


