Skip to content

Instantly share code, notes, and snippets.

@JohnReeves
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohnReeves/af2ff7f8b1973a58017e to your computer and use it in GitHub Desktop.
Save JohnReeves/af2ff7f8b1973a58017e to your computer and use it in GitHub Desktop.
#Mouse Handling using Tkinter
A minimal mouse handling script, clearly using tkinter. Clumsily importing *
```python
from tkinter import *
#Globals
lastx, lasty = 0, 0
#Definitions
def xy(event):
global lastx, lasty
lastx, lasty = event.x, event.y
def addLine(event):
global lastx, lasty
canvas.create_line((lastx, lasty, event.x, event.y))
lastx, lasty = event.x, event.y
#Create a top level object
window = Tk()
#Canvas Create + Setup
canvas = Canvas(root)
canvas.grid(column=0, row=0, sticky=(N, W, E, S))
canvas.bind("<Button-1>", xy)
canvas.bind("<B1-Motion>", addLine)
#Main Loop
window.mainloop()
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment