Created
October 7, 2017 08:43
-
-
Save ben-cohen/e74ecb4533d0fcc3bd6419ea5702a756 to your computer and use it in GitHub Desktop.
Display "breadcrumb trail" to test mouse motion events
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
#!/usr/bin/python | |
# | |
# Ben Cohen, October 2017. | |
# | |
# mouse_motion.py: Display "breadcrumb trail" to test mouse motion events. | |
# | |
# Move the mouse and the positions of the motion events will be displayed. | |
# Clear the canvas by pressing Backspace. Quit by pressing Escape. | |
import sys | |
if sys.version_info[0] == 2: | |
import Tkinter as tk | |
else: | |
import tkinter as tk | |
class MouseMotionTest(object): | |
def __init__(self, master, **kwargs): | |
self.master = master | |
master.attributes("-zoomed", True) # or could use "-fullscreen" | |
master.title("Mouse motion test") | |
master.bind('<Escape>',self.quit) | |
master.bind('<BackSpace>',self.clear) | |
canvas = tk.Canvas(master) | |
canvas.pack(expand = tk.YES, fill = tk.BOTH) | |
canvas.bind('<Motion>',self.mousemoved) | |
canvas.config(cursor = "top_left_arrow") | |
self.canvas = canvas | |
def quit(self, event): | |
self.master.quit() | |
def clear(self, event): | |
self.canvas.delete("all") | |
def mousemoved(self, event): | |
x = event.x | |
y = event.y | |
self.canvas.create_line(x - 3, y, x + 3, y, fill = "#000000") | |
self.canvas.create_line(x, y - 3, x, y + 3, fill = "#000000") | |
root=tk.Tk() | |
app=MouseMotionTest(root) | |
root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment