Apr-16-2020, 04:56 AM
I entered into the program correction bot coefficients from the current bot direction. Now shows the exact value of the angle.
import tkinter as tk from tkinter import* import math root = tk.Tk() root.geometry('500x500+2+10') def target(event): bot_center_x = canvas1.coords(bot)[0] + 15 bot_center_y = canvas1.coords(bot)[1] + 15 clik_x = event.x clik_y = event.y angle(bot_center_x, bot_center_y, clik_x, clik_y) def angle(bot_center_x, bot_center_y, clik_x, clik_y): if angle_mov == 'nord': #current bot direction k1 = 90 k2 = 270 elif angle_mov == 'east': #current bot direction pass elif angle_mov == 'south':#current bot direction pass elif angle_mov == 'west': #current bot direction pass if clic_x >= bot_x: angle_grad = int(math.degrees(math.atan((clic_y - bot_center_y) / (clic_x - bot_center_x))) + k1) else: angle_grad = int(math.degrees(math.atan((clic_y - bot_center_y) / (clic_x - bot_center_x))) + k2) print('angle: '+str(angle_grad)) canvas1 = Canvas(root, width = 500, height = 500) canvas1.place(x = 0, y = 0) bot = canvas1.create_oval(200, 200, 230, 230) angle_mov = 'nord' #current bot direction root.bind('<Button-1>', target) root.mainloop()