时间: 2018-11-27
摘要:画画
Python画画的一些例子代码学习用rectangle画方块。 采用for循环控制100-999个个数,每个数分解为一位、十位、百位。 程序源代码:
from tkinter import Tk,Canvas
顶=tk ()
c=canvas(width=300,height=300,bg='white ' ) ) ) ) ) ) ) )。
foriinrange (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 .包() ) ) )。
top.mainloop ()
学习在line上画直线:
from tkinter import Tk,Canvas
来自匹配导入sin、cos、pi
line1=[ (15,16 )、45,36 )、67,45 )、1,90 )、66,90,100 )、234,22 )、256,23 ],
(1,288 ),) 150,150 ) ]
line2=[ (15,15 ),(285,284 ) ]
顶=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
forIinrange(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 .包() ) ) )。
top.mainloop ()
在circle上学习画圆:
from tkinter import Tk,Canvas
顶=tk ()
c=canvas(width=300,height=300,bg='white ' ) ) ) ) ) ) ) )。
不,变成了膏药旗
c.create _ oval (100,100,200,200,outline='red ',fill='red ' )
c .包() ) ) )。
top.mainloop ()