时间:2018-11-27
概述:画图
Python画图的一些例子代码,学用rectangle画方形。利用for循环控制100-999个数,每个数分解出个位,十位,百位。程序源代码:
from tkinter import Tk, Canvas
top=Tk()
c = Canvas(width=300, height=300, bg='white')
for i in range(1,11):
x1=150-i*10
y1=150-i*5
x2=150+i*10
y2=150+i*5
c.create_rectangle(x1,y1,x2,y2,outline='red')
c.pack()
top.mainloop()
学用line画直线:
from tkinter import Tk, Canvas
from math import sin,cos,pi
line1=[(15,16),(45,36),(67,45),(1,90),(66,90),(90,100),(234,22),(256,23),
(1,288),(150,150)]
line2=[(15,15),(285,284)]
top=Tk()
c = Canvas(width=300, height=300, bg='white')
c.create_line(line1,fill='blue',dash=(4,2))
c.create_line(line2,fill='yellow')
cx=cy=150
r=100
for i in range(361):
nx=cos(pi*i/180)*r+150
ny=sin(pi*i/180)*r+150
c.create_line(cx,cy,nx,ny,fill='red')
c.pack()
top.mainloop()
学用circle画圆形:
from tkinter import Tk, Canvas
top=Tk()
c = Canvas(width=300, height=300, bg='white')
#靠,画成了个膏药旗
c.create_oval(100,100,200,200,outline='red',fill='red')
c.pack()
top.mainloop()