我看到这篇文章: How to draw a polygon on a tkinter canvas using a class?
但是当我试图画一个正方形时:
from Tkinter import*
root = Tk()
class GUI(Canvas):
'''inherits Canvas class (all Canvas methodes, attributes will be accessible)
You can add your customized methods here.
'''
def __init__(self,master,*args,**kwargs):
Canvas.__init__(self, master=master, *args, **kwargs)
polygon = GUI(root)
polygon.create_polygon([0, 0, 100, 100, 100, 0, 100], outline='gray', fill='gray', width=2)
polygon.pack()
root.mainloop()
我得到了这个:
expected even number: got 7
我尝试了所有我能想到的东西,但我无法让它发挥作用!
答案 0 :(得分:1)
当create_polygon
方法请求偶数个参数时,为什么不提供偶数?
[x0, y0, x1, y1, ...]
方法将polygon.create_polygon([0, 0, 100, 0, 100, 100, 0, 100], outline='gray', fill='gray', width=2)
形式的参数与(x0,y0),...作为多边形的顶点。每个顶点有2个坐标,因此参数的数量必须是偶数。
(0,0)
适用于包含顶点(100,0)
,(100,100)
,(0,100)
,x <- seq(-4, 4, length = 10)
y <- exp(x) / (1 + exp(x))
par(mfrow=c(1,2))
plot(x, y, ylim=range(y), xlim=c(-4, 4))
plot(x, y, ylim=range(y), xlim=rev(c(-4, 4)))
的正方形。