相关 tkinter 的介绍:Python 55,56
目录
57.题目:画图,学用line画直线。
58.题目:画图,学用rectangle画方形。
57.题目:画图,学用line画直线。
#57
from tkinter import *canvas = Canvas(width=300, height=300, bg='green')
canvas.pack(expand=YES, fill=BOTH)
x0 = 263
y0 = 263
y1 = 275
x1 = 275
for i in range(19):canvas.create_line(x0,y0,x0,y1, width=1, fill='red')x0 = x0 - 5y0 = y0 - 5x1 = x1 + 5y1 = y1 + 5x0 = 263
y1 = 275
y0 = 263
for i in range(21):canvas.create_line(x0,y0,x0,y1,fill = 'red')x0 += 5y0 += 5y1 += 5mainloop()
输出:
58.题目:画图,学用rectangle画方形。
程序分析:
rectangle(int left, int top, int right, int bottom)
参数说明:(left ,top )为矩形的左上坐标,(right,bottom)为矩形的右下坐标,两者可确定一个矩形的大小
#58
from tkinter import *
root = Tk()
root.title('Canvas')
canvas = Canvas(root,width = 500,height = 500,bg = 'yellow')
x0 = 263
y0 = 263
y1 = 275
x1 = 275
for i in range(19):canvas.create_rectangle(x0,y0,x1,y1)x0 -= 5y0 -= 5x1 += 5y1 += 5canvas.pack()
root.mainloop()
输出: