The lines drawn on a Tkinter.Canvas
are not smooth. How can they be made smooth?
Here's what I tried:
from Tkinter import *
root = Tk()
cv = Canvas(root,bg = 'white')
rt1 = cv.create_rectangle(10,10,110,110,width = 8,tags = ('r1','r2','r3'))
def printRect(event):
print 'rectangle'
def printLine(event):
print 'line'
cv.tag_bind('r1','<Button-1>',printRect)
cv.tag_bind('r1','<Button-3>',printLine)
cv.create_line(10,20,200,200,width = 5,tags = 'r1')
cv.pack()
root.mainloop()
Here's what it looks like:
To draw a line on a Canvas, we can use create_line(x,y,x1,y1, **options) method. In Tkinter, we can draw two types of lines: simple and dashed.
A Frame is designed to be a parent container of other widgets. A Canvas is like a canvas that you can draw somethings on it like lines, circles, text, etc. A Canvas can be used as a parent container as well but it is not designed for that at the first place.
Build A Paint Program With TKinter and Python While creating a canvas in tkinter, it will effectively eat some memory which needs to be cleared or deleted. In order to clear a canvas, we can use the delete() method. By specifying “all”, we can delete and clear all the canvas that are present in a tkinter frame.
A tkinter canvas can be used to draw in a window. Use this widget to draw graphs or plots. You can even use it to create graphical editors. You can draw several widgets in the canvas: arc bitmap, images, lines, rectangles, text, pieslices, ovals, polygons, ovals, polygons, and rectangles.
Tkinter
graphics are not anti-aliased which is why the diagonal line appears jagged. There may be a platform specific work-around like this one I found titled Drawing Anti-Aliased Graphics Under Tkinter/Windows to provide the functionality you desire.
You might try to do some antialiasing of the poor, by drawing a clearer colored one pixel larger second line before (under) the first one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With