Last active
August 29, 2015 14:00
-
-
Save JohnReeves/af2ff7f8b1973a58017e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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