对于重复标记:我完全知道其中有一些类似的问题matplotlib
,例如这个。我的问题是关于Tkinter
没有matplotlib
。
我现在将Lena导入python并在她的帽子上画一个绿色的点
In [72]: from PIL import Image
....: import matplotlib.pylab as plt
....: im = Image.open('lena.jpg')
....: fig = plt.figure()
....: axes = fig.add_axes([0.1, 0.1, 0.8, 0.8])
....: axes.imshow(im)
....: axes.scatter(50, 50, marker='s', color='green')
Out[72]: <matplotlib.collections.PathCollection at 0xb3e2ef0>
(请忽略红点)
现在,我希望绿点(50, 50)
仍在Lena的帽子上,但我也希望在左下角而不是左上角绘制绿点。
我期望这样的事情:
如图所示,我设法通过matplotlib
另外一行轻松地做到这一点:
axes.invert_yaxis()
我现在在的画布上绘画Tkinter
。我怎样才能达到同样的效果?
更新资料
莉娜只是为了说明我的目的。在我真正的问题中,我没有在中导入任何内容Tkinter
。我只是在一块空的画布上画画。我不愿意修改我的数据,我只希望将图纸倒过来。就像我的Lena插图一样,坐标仍然是(50, 50)
。区别在于现在它在左下角而不是上角。
在我看来,使用如下代码很简单:
import Tkinter
#Set up a basic canvas
top = Tkinter.Tk()
canv = Tkinter.Canvas(top, bg="brown", height=250, width=300)
#Replace with what ever values you want
x = 50
y = 50
#Draw the first dot
line1 = canv.create_line(x, y, x - 2, y - 2, fill="green", width=3)
#This next line is pretty much all it takes to find the Y inverse
y = canv.winfo_reqheight() - y
#Draw the second dot
line2 = canv.create_line(x, y, x - 2, y - 2, fill="green", width = 3)
canv.pack()
top.mainloop()
这将返回以下内容:
基本上,我要做的就是获取画布高度(250),并从中减去先前的Y值(50),从而返回Y倒数(200)。不完全是内置函数,但实际的翻转部分非常简单。希望那是您想要的...祝您好运!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句