Python实例 63,64

2021/12/27 20:37:13

本文主要是介绍Python实例 63,64,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

目录

63.题目:画椭圆

1.tkinter画椭圆

 2.turtle画椭圆

 64.题目:利用ellipse 和 rectangle 画图


63.题目:画椭圆

1.tkinter画椭圆

#63
from tkinter import *
x = 360
y = 160
top = y - 30
bottom = y - 30

canvas = Canvas(width = 500,height = 600,bg = 'white')
for i in range(20):
    canvas.create_oval(250 - top,250 - bottom,250 + top,250 + bottom)
    top -= 5
    bottom += 5
canvas.pack()
mainloop()

 输出:

 2.turtle画椭圆

import turtle
 
pen=turtle.Turtle()                #定义画笔实例
a=1
for i in range(120):                
    if 0<=i<30 or 60<=i<90:        #控制a的变化
        a=a+0.2
        pen.lt(3)                  #向左转3度
        pen.fd(a)                  #向前走a的步长
    else:
        a=a-0.2
        pen.lt(3)
        pen.fd(a)
 
print(pen)
turtle.mainloop()

输出:

 64.题目:利用ellipse 和 rectangle 画图

from tkinter import *
canvas = Canvas(width = 400,height = 600,bg = 'white')
left = 20
right = 50
top = 50
num = 15
for i in range(num):
    canvas.create_oval(250 - right,250 - left,250 + right,250 + left)
    canvas.create_oval(250 - 20,250 - top,250 + 20,250 + top)
    canvas.create_rectangle(20 - 2 * i,20 - 2 * i,10 * (i + 2),10 * ( i + 2))
    right += 5
    left += 5
    top += 10

canvas.pack()
mainloop()

输出:

 



这篇关于Python实例 63,64的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程