python tkinter坐标转换

tkinter中坐标原点在左上角,横坐标向右,纵坐标向下,画图需要将坐标转换成右下角的某个点来符合我们的常用坐标

坐标原点设为(x0,y0),横坐标向右,纵坐标向上,:

转换:想实现坐标点(x,y)的显示

          实际显示点坐标是(x0+x,y0-y)

 

并且,tkinter中的create_line函数的逻辑是graph.create(point),这里的point是个list,成分是[x0,y0,x1,y1,x2,y2..............] ,然后结果是将(x0,y0),(x1,y1),(x2,y2)等,连成一条线

xlinepoint=[20,500,900,500]
ylinepoint=[20,500,20,20]
xy=[20,500,20+40,500-40,20+120,500-200]



traceID = graph.create_oval(20-1,500-1,20+1,500+1,fill='black')
traceID1=   graph.create_line(xlinepoint,fill='black')
traceID1=   graph.create_line(ylinepoint,fill='black')
traceID1=   graph.create_line(xy,fill='black')

以上程序实现的是坐标原点移到(20,500)后显示原点 (40,40),(120,200)三点的连线;xlinepoint是横坐标画线,ylinepoint是纵坐标画线

posted @ 2019-06-05 17:29  mghhz816  阅读(991)  评论(0编辑  收藏  举报