#圆from tkinter import *canvas = Canvas(width=800, height=600, bg='yellow')#声明窗口属性canvas.pack(expand=YES, fill=BOTH)k = 1j = 1for i in range(0, 26): canvas.create_oval(310 - k, 250 - k, 310 + k, 250 + k, width=1)#画圆 k += j j += 1mainloop()#执行整个函数
执行结果:
#直线from tkinter import *canvas =Canvas(width=300,height=300,bg='white')#声明窗口属性canvas.pack(expand=YES,fill=BOTH)#执行窗口属性x0 = 260#声明坐标y0 = 260y1 = 90for i in range(10): canvas.create_line(x0,y0,x0,y1, width=1, fill='red')#画直线 x0 = x0 - 5 y0 = y0 - 5 y1 = y1 + 5mainloop()#执行整个函数
执行结果:
#矩形from tkinter import *canvas =Canvas(width=300,height=300,bg='white')#声明窗口属性canvas.pack(expand=YES,fill=BOTH)#执行窗口属性x0 = 263y0 = 263y1 = 275x1 = 275for i in range(19): canvas.create_rectangle(x0, y0, x1, y1) x0 -= 5 y0 -= 5 x1 += 5 y1 += 5mainloop()
执行结果: