'Smoothen the Outline of Tkinter Circle Graphic
Below is a pared down copy of the code used for creating a circle in Tkinter using Python. I have the method self.drawCircle() which uses the create_oval() function on the canvas self.c. As you will see when you run the program, the circle is not very clear. There are many jagged edges in the final display. For example if you look at the 4 cardinal points on the circle, NSEW, all of them show a flat line of roughly 10 pixels long rather than a nice smooth curve.
Is there a way to create a smoother circle?
from tkinter import *
class MainWindow:
def __init__(self, master):
# Master Window
self.master = master
# Instantiate frames
self.frame0 = Frame(self.master, bd=5, padx=5, bg='#448833') # Top long row
# Place frames
self.frame0.grid(row=0, column=0, columnspan=2, sticky="nsew")
self.drawCircle(100, 100, 300, 300,10) # draws circle
def drawCircle(self,x1,y1,x2,y2, width):
''' inputs: 4 ints: coordinates of square, top left, and bottom right.'''
# Create a canvas object
self.c = Canvas(self.frame0, width=500, height=400, bg='white')
# Draw an Oval in the canvas
self.c.create_oval(x1,y1,x2,y2, width=width)
self.c.grid(row=1,column=2,sticky='nse')
def main():
root = Tk()
MainWindow(root)
root.mainloop()
main()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
