Skip to content

Instantly share code, notes, and snippets.

@secantsquared
Created November 1, 2020 18:23
Show Gist options
  • Save secantsquared/60f68767c181c2448a6cf84003b371e6 to your computer and use it in GitHub Desktop.
Save secantsquared/60f68767c181c2448a6cf84003b371e6 to your computer and use it in GitHub Desktop.
click events in tkinter
import tkinter as tk
# Instantiate tkinter app
app = tk.Tk()
# Create example callback functions to use during click event
def leftclick(event):
print("left")
def middleclick(event):
print("middle")
def rightclick(event):
print("right")
# Create a basic frame
frame = Frame(var, width=300, height=250)
# Bind three buttons in the frame to the callbacks
frame.bind("<Button-1>", leftclick)
frame.bind("<Button-2>", middleclick)
frame.bind("<Button-3>", rightclick)
# Pack frame
frame.pack()
# Run main loop
app.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment