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

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.

  • Things may have changed with tcl8.5: wiki.tcl.tk/10101 – Reblochon Masque May 1 at 6:21
  • @ReblochonMasque: Don't think so. The linked discussion is primarily about the rendering of text. – martineau May 1 at 14:27
  • Yes, good point, I noticed that too; this is why I wrote that it may have changed. – Reblochon Masque May 1 at 15:32

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.