最简单的直线也能画出漂亮的图案来:
import tkinter as tk import pyautogui as ag from time import sleep def Line01(): for j in range(1, 9): tCanvas.delete("all") coord = 5, 5, 635, 360 tCanvas.create_rectangle(coord) for i in range(5, 635, j): coord = 5, 5, i, 360 tCanvas.create_line(coord) coord = 635, 360, i, 5 tCanvas.create_line(coord) coord = 5, 360, 635, 400 tCanvas.create_rectangle(coord) tCanvas.create_text((20, 380), text=u'莫尔条纹,直线动端的间隔 = ' + str(j), anchor=tk.W, font=("宋体", 9)) tCanvas.update() sleep(1) def Line02(): tCanvas.delete("all") coord = 155, 5, 510, 360 tCanvas.create_rectangle(coord) coord = 5, 360, 635, 400 tCanvas.create_rectangle(coord) tCanvas.create_text((20, 380), text=u'直线逼近圆弧,相当于不停地给圆作切线', anchor=tk.W, font=("宋体", 9)) for j in range(5,0,-1): for i in range(0,510-155,j): coord = 155+i, 5, 510, 5+i tCanvas.create_line(coord) tCanvas.update() sleep(1) coord = 155, 5, 510, 360 tCanvas.create_rectangle(coord,fill='white') for i in range(0,510-155,5): coord = 155+i, 5, 510, 5+i tCanvas.create_line(coord) coord = 155, 360-i, 155+i, 5 tCanvas.create_line(coord) coord = 155+i, 360, 510, 360-i tCanvas.create_line(coord) coord = 155, 5+i, 155+i, 360 tCanvas.create_line(coord) tCanvas.update() sleep(1) if __name__ == '__main__': win = tk.Tk() X, Y = ag.size() winSize = "640x480" winPos = winSize + "+" + str((X - 640) // 2) winPos += "+" + str((Y - 480) // 2) win.geometry(winPos) win.resizable(False, False) title = u'桌面分辨率:' + str(X) + "x" + str(Y) title += ' ' * 5 + u'窗体大小:' + winSize win.title(title) win.update() tCanvas = tk.Canvas(win, width=win.winfo_width(), height=400, bg='white') tCanvas.pack(side="top") tk.Label(win, text=u"画布作图,请点击上面的按钮").pack(side="bottom") tButton1 = tk.Button(win, text=u'莫尔条纹', command=Line01) tButton1.place(width=100, height=35, x=200, y=415) tButton2 = tk.Button(win, text=u'直线切图', command=Line02) tButton2.place(width=100, height=35, x=340, y=415) win.mainloop()
效果图: