Why are the Tkinter canvas lines jagged?

风流意气都作罢 提交于 2019-11-30 08:31:36

问题


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:


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/12436147/why-are-the-tkinter-canvas-lines-jagged

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!