Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_xy_degrees_and_distance.py
- from Tkinter import *
- from PIL import ImageDraw, ImageTk, Image, ImageGrab
- import math
- import random
- root = Tk()
- root.title("Tk_xy_degrees_and_distance".replace('_',' '))
- ### root.withdraw() # vs root.deiconify()')
- xx,yy = 600,600
- canvas = Canvas(root, width=xx, height=yy)
- canvas.grid()
- mouse = [xx/2,yy/2]
- def mmove(event):
- mouse[:] = [z*1.0 for z in (event.x,event.y)]
- canvas.bind('<Motion>',mmove)
- def dist(a,b):
- return (abs(a)**2+abs(b)**2)**0.5
- def degrees(x1,y1,x2,y2):
- return (math.degrees(math.atan2((x2-x1),(y2-y1)*-1))+90)%360 if (y2-y1) else 0.0
- while 1:
- canvas.delete('all')
- xm, ym = mouse
- deg = degrees(xx/2, yy/2, xm, ym)
- distance = dist(xx/2-xm, yy/2-ym)
- canvas.create_line(xx/2, yy/2, xm, ym, fill='blue')
- canvas.create_text(20, 20, anchor='nw', font='simsun 20', text='degrees: %f'%deg)
- canvas.create_text(20, 50, anchor='nw', font='simsun 20', text='distance: %f'%distance)
- t = 'x: %d y: %d +++(%d,%d)'%(xm, ym, xm-xx/2, ym-yy/2)
- canvas.create_text(20, 80, anchor='nw', font='simsun 20', text=t)
- canvas.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement