Reputation: 163
I am drawing arcs in tkinter. They use the 'arc' method so only have an outer edge of a specified width and colour. Annoyingly some arcs seem to have randomly have a rounded edge. Does anyone know if this is a bug or if it can be fixed?
Example code:
w1.create_arc(xarc0,yarc0,xarc1,yarc1,start=arcstart,extent=arcextent,width=thick1,outline=mc,style="arc")
Pic of the problem attached.
Upvotes: 2
Views: 1612
Reputation: 1
Well, this is six years later and, guess what, I have hit this problem using the call from PySimpleGUI (ver 4.60.5). The Tkinter version looks like 8.6.10.
This problem came into view right at the end of my application development and really sucks. Like the example above the weird semi-circular error only appears at two degrees around the 0,90,180,270 quadrants
The only easy workaround I can see is to do multiple single arcs but that is a waste of CPU and may not work as intended either.
I am going to have a look at the code in case there is something obvious there. After that I may write my own and one which uses more logical parameters such as centre location, radius, colour, width.
13/02/2024 - Update
The problem with quadrants was solved, or more correctly, bypassed with this code here.
canvas.draw_arc has problems with fills at the quadrants. This version significantly improves the filled arcs by drawing a series of arcs with different radii. As this fix only works with arcs where the arc and fill are the same colour we only expect arc_colour.
def draw_arc_2_improved(self, arc_center_xy, arc_radius, arc_beg_angle, arc_end_angle, arc_width=1, arc_colour='yellow'): global window fill_colour = arc_colour # We are only drawing solid filled arcs here.
if arc_width > 1:
for radius_offset in range(arc_width - 1): # as we are drawing arcs of width 2 we need to reduce by 1
self.draw_arc_2((0, 0), (arc_radius-radius_offset), arc_beg_angle, arc_end_angle, arc_width=2, fill_colour=fill_colour, arc_colour=fill_colour)
else: # Draw single pixel width arc
self.draw_arc_2((0, 0), arc_radius, arc_beg_angle, arc_end_angle, arc_width=1, fill_colour=fill_colour, arc_colour=fill_colour)
Upvotes: 0
Reputation: 5349
After some experimenting, I believe this is a glitch
I ran a simulation to create 360 arcs, each with an extent from 1 - 360
, I found that the only time when the arc has a curved end was when the extent of the arc was 90 or 271, I don't know why this happens but I don't think its supposed to.
The green arc is the simulation, the red and the blue arc are the arcs which have a curved end. I don't think there is a way to fix this problem, however you can change the extent from 90 to 91 as I've done for the orange arc, as you can see it has a straight end and there's not much difference.
Here's the code if you want to play around with it:
from tkinter import *
Window = Tk()
w1 = Canvas(Window)
w1.pack()
for x in range(360):
w1.after(5)
arc = w1.create_arc(20, 20, 150,100,start=0,extent=x,width=30,outline = "green", style="arc")
w1.update()
if x == 90 or x == 271:
print("Now!")
w1.create_arc(160,20, 300,100,start=0,extent=90,width=30,outline = "red", style="arc")
w1.create_arc(180,120, 320,200,start=0,extent=271,width=30,outline = "blue", style="arc")
w1.create_arc(0, 150, 140,230,start=0,extent=91,width=30,outline = "orange", style="arc")
Upvotes: 2