user1653363
user1653363

Reputation: 405

Why are the Tkinter canvas lines jagged?

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:

tkinter output from sample code

Upvotes: 13

Views: 10384

Answers (3)

martineau
martineau

Reputation: 123393

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.

Upvotes: 8

xiaoyifang
xiaoyifang

Reputation: 949

  1. draw an antialias image (using Image PIL ,numpy,opencv etc)
  2. show the image on the canvas.

Upvotes: 1

Camion
Camion

Reputation: 1374

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.

Upvotes: 1

Related Questions