Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_snaptext2grid.py
- import Tkinter as tk
- def Snap2Grid(width=300, height=300):
- canvas.config(width=width, height=height)
- def onClick1(event):
- canvas.click = event.x, event.y
- canvas.delete('cpoint')
- def onMotion1(event):
- x, y = canvas.click
- dx = event.x - x
- dy = event.y - y
- canvas.move('current' ,dx ,dy)
- canvas.click = event.x, event.y
- def onRelease1(event):
- mx, my = event.x, event.y
- x, y = max(0, mx-(mx%150))+75, my-(my%30)+16
- canvas.coords("R", x,y)
- canvas.create_line(width/2,0, width/2,height)
- for y in range(1,height,30):
- canvas.create_line(0,y, width,y)
- canvas.create_text(150, 60, text='drag this text', font=('arial', 18),
- fill="red", activefill='green', tag="R")
- canvas.tag_bind("R", "<Button-1>", onClick1)
- canvas.tag_bind("R", "<B1-Motion>", onMotion1)
- canvas.tag_bind("R", "<ButtonRelease-1>",onRelease1)
- 0
- root = tk.Tk()
- canvas = tk.Canvas()
- canvas.pack()
- canvas.click = None
- Snap2Grid()
- '''
- if text in c.find_overlapping(str(x-10), str(y-10), str(x+10), str(y+10)):
- c.coords(text, x, y) # move text to mouse position
- '''
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement