题目:画图,学用rectangle画方形。

rectangle(int left, int top, int right, int bottom)

参数说明:(left ,top )为矩形的左上坐标,(right,bottom)为矩形的右下坐标,两者可确定一个矩形的大小

Canvas

#!usr/bin/env python
# -*- coding: utf-8 -*-

if __name__ == '__main__':        
	from Tkinter import *    #导入库
	root = Tk()          #创建一个根窗口,其它事件将在这之上
	root.title('Canvas')     #定义窗口标题
	canvas = Canvas(root, width = 400,height = 400,bg = 'yellow')  #在根窗口上绘制宽高400 背景颜色为黄色的窗口
	x0 = 200
	y0 = 200
	y1 = 200
	x1 = 200    #初始点设置
	for i in range(19):    #进入循环,调用create_rectangle函数绘制矩形框
		canvas.create_rectangle(x0, y0, x1, y1) 
		x0 -= 5
		y0 -= 5
		x1 += 5
		y1 += 5

	canvas.pack()    #绘制图案显示
	root.mainloop()    #根窗口事件循环

 效果图:

 

 

posted on 2016-12-08 14:38  Rohero  阅读(713)  评论(0编辑  收藏  举报