I’m starting out in programming and I’m having difficulty creating this graph.
`I’m trying to place the graph numbers in order of 0, 45, 90, 174, 178, 90 -45, I’m having trouble placing the 0 to be on the left of the image. If anyone can give me any tips on how to do this, I would be grateful in advance. I’ve already tried a breakpoint to visualize the angle but I didn’t get any results.
enter image description here`
import tkinter as tk
import math
class CircleArrowApp:
def init(self, master):
self.master = master
master.title(“HORSTFX”)
self.radius = 100 # Sets the initial radius of the circles
# Creating the first circle and its arrow
self.canvas1 = tk.Canvas(master, width=400, height=400, bg='white', highlightbackground='goldenrod', highlightthickness=15)
self.canvas1.pack(side=tk.LEFT, padx=20)
self.angle1 = 0
self.arrow1 = None
self.canvas1.bind("<Configure>", self.on_canvas1_resize)
# Creation of the second circle and its arrow
self.canvas2 = tk.Canvas(master, width=400, height=400, bg='white', highlightbackground='goldenrod', highlightthickness=15)
self.canvas2.pack(side=tk.LEFT, padx=20)
self.angle2 = 0
self.arrow2 = None
self.canvas2.bind("<Configure>", self.on_canvas2_resize)
# Creating the buttons
self.button_frame = tk.Frame(master)
self.button_frame.pack(side=tk.BOTTOM, padx=10)`
self.start_button = tk.Button(self.button_frame, text="START", width=10, command=self.start_animation)
self.start_button.pack(side=tk.TOP, pady=10)
self.stop_button = tk.Button(self.button_frame, text="STOP", width=10, command=self.stop_animation)
self.stop_button.pack(side=tk.TOP, pady=10)
self.plus_button = tk.Button(self.button_frame, text="+", width=10, command=self.plus_function)
self.plus_button.pack(side=tk.TOP, pady=10)
self.minus_button = tk.Button(self.button_frame, text="-", width=10, command=self.minus_function)
self.minus_button.pack(side=tk.TOP, pady=10)
self.animating = False
self.animate()
def start_animation(self):
self.animating = True
def stop_animation(self):
self.animating = False
def plus_function(self):
self.radius += 10
self.update_circle_arrows()
def minus_function(self):
if self.radius > 10:
self.radius -= 10
self.update_circle_arrows()
def draw_circle_arrow(self, canvas, angle):
center_x = canvas.winfo_width() // 2
center_y = canvas.winfo_height() // 2
# Set the size of the inner circle relative to the border
inner_radius = self.radius * 0.8
# Draw the circle with white fill and yellow border
canvas.create_oval(center_x - inner_radius, center_y - inner_radius, center_x + inner_radius, center_y + inner_radius, outline='goldenrod', fill='white', width=8)
# Calculate the arrow's endpoints
end_x = center_x + inner_radius * math.cos(angle)
end_y = center_y + inner_radius * math.sin(angle)
# Draw the arrow moving inside the circle
start_x = center_x
start_y = center_y
canvas.create_line(start_x, start_y, end_x, end_y, arrow=tk.LAST, fill='goldenrod', width=6)
if canvas == self.canvas1:
if self.arrow1:
canvas.delete(self.arrow1)
self.arrow1 = canvas.create_line(center_x, center_y, end_x, end_y, arrow=tk.LAST, fill='goldenrod', width=6)
# Adiciona os números no círculo exterior do canvas1
outer_radius = inner_radius + 20
for i in [0, -135, 90, -45, 0, 45, 90, 135, 178]:
angle_rad = math.radians(-i)
num_x = center_x + outer_radius * math.cos(angle_rad)
num_y = center_y + outer_radius * math.sin(angle_rad)
canvas.create_text(num_x, num_y, text=str(i), fill='black')
# Draw the outer circle of canvas1
outer_radius = inner_radius + 2
canvas.create_oval(center_x - outer_radius, center_y - outer_radius, center_x + outer_radius, center_y + outer_radius, outline='', width=2)
elif canvas == self.canvas2:
if self.arrow2:
canvas.delete(self.arrow2)
self.arrow2 = canvas.create_line(center_x, center_y, end_x, end_y, arrow=tk.LAST, fill='goldenrod', width=6)
# Add the numbers to the outer circle
outer_radius = inner_radius + 20
for i in [0, -135, 90, -45, 0, 45, 90, 135, 178]:
angle_rad = math.radians(-i)
num_x = center_x + outer_radius * math.cos(angle_rad)
num_y = center_y + outer_radius * math.sin(angle_rad)
canvas.create_text(num_x, num_y, text=str(i), fill='black')`
Moysés Requiao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.