Python 練習實例58
python 練習實例58
題目:畫圖,學用rectangle畫方形。
程序分析:
rectangle(int left, int top, int right, int bottom)
參數說明:(left ,top )為矩形的左上坐標,(right,bottom)為矩形的右下坐標,兩者可確定一個矩形的大小
實例(python 2.0+):
#!/usr/bin/python # -*- coding: utf-8 -*- if __name__ == '__main__': from tkinter import * root = tk() root.title('canvas') canvas = canvas(root,width = 400,height = 400,bg = 'yellow') x0 = 263 y0 = 263 y1 = 275 x1 = 275 for i in range(19): canvas.create_rectangle(x0,y0,x1,y1) x0 -= 5 y0 -= 5 x1 += 5 y1 += 5 canvas.pack() root.mainloop()
以上實例輸出結果為:
