猫史档案馆


【Python作品分享】【36强进10】给航天员的明信片 —— 张斐梵

用户:成熟的炸弹人Honq成熟的炸弹人Honq查看:0 回复:0 评论:0 创建时间:2021-05-23T20:50:21


【作品展示】

center_image

 

【作品介绍】

这个明信片展示了中国航天的三大里程碑。我用海龟库画出了卡片,写出了文字,也印上了图片。我也导入了easygui模块在最开头做一些小小的互动。希望大家喜欢!

 

【作品源代码】

import turtle,easygui
p,s = turtle.Pen(),turtle.Screen()
turtle.pencolor('oldlace')
turtle.hideturtle()
w,h = 1250,750
text = [
    "致航天人:\n 人类的飞天梦想,\n祖国的太空战略,\n离不开,\n你们的辛勤和智慧!\n",
    ["期待未来和你们","一起探索宇宙!"],
    ["张斐梵","2021年5月23日"]
]
text_split1,text_split2,text_split3,text_split4,text_split5 = text[0].split('\n')[0:5]
text[0] = [text_split1,text_split2,text_split3,text_split4,text_split5]
def goto_pos(x,y,penname=p):
    penname.penup()
    penname.goto(x,y)
    penname.pendown()
s.setup(600,600)
s.bgcolor('black')
p.fillcolor('oldlace')
p.hideturtle()
p.speed(6)
p.penup()
p.backward(w/2)
p.right(90)
p.forward(h/2)
p.pendown()
p.left(90)
p.begin_fill()
for x in range(2):
    p.forward(w)
    p.left(90)
    p.forward(h)
    p.left(90)
p.end_fill()
p.right(90)
p.backward(h)
p.goto(0,0)
p.goto(w/2,h/2)
goto_pos(0,-10)
p.pencolor('red')
p.write('给航天人的明信片',font=('宋体',20),align='center')
p.pencolor('navyblue')
choice = easygui.ccbox('有一张给航天人的明信片!请问要拿出来吗?','新发现',('是','否'))
if choice == True:
    p.clear()
    goto_pos(-625,-375)
    p.left(90)
    p.begin_fill()
    for x in range(2):
        p.forward(w)
        p.left(90)
        p.forward(h)
        p.left(90)
    p.end_fill()
    for x in ("satellite.gif","astronaut.gif","astronaut2.gif","moon2.gif","mars2.gif"):
        s.addshape(x)
    #东方红一号
    goto_pos(-420,220,turtle)
    turtle.shape("satellite.gif")
    turtle.stamp()
    goto_pos(-275,55)
    p.pencolor('red')
    p.write('1970年,东方红一号',font=('宋体',25),align='right')
    #嫦娥一号
    goto_pos(-40,-200,turtle)
    turtle.shape('moon2.gif')
    turtle.stamp()
    goto_pos(75,-40)
    p.write('2007年,嫦娥一号',font=('宋体',25),align='right')
    #天问一号
    goto_pos(375,220,turtle)
    turtle.shape("mars2.gif")
    turtle.stamp()
    goto_pos(490,50)
    p.write('2021年,天问一号',font=('宋体',25),align='right')
    #文字
    p.pencolor('navyblue')
    goto_pos(-180,300)
    p.speed(8)
    for x in text[0][0]:
        p.write(x,font=('宋体',30),align='center')
        p.penup()
        p.forward(40)
        p.pendown()
    goto_pos(-180,260)
    for x in text[0][1]:
        p.write(x,font=('宋体',30),align='center')
        p.penup()
        p.forward(40)
        p.pendown()
    goto_pos(-180,220)
    for x in text[0][2]:
        p.write(x,font=('宋体',30),align='center')
        p.penup()
        p.forward(40)
        p.pendown()
    goto_pos(-180,180)
    for x in text[0][3]:
        p.write(x,font=('宋体',30),align='center')
        p.penup()
        p.forward(40)
        p.pendown()
    goto_pos(-180,140)
    for x in text[0][4]:
        p.write(x,font=('宋体',30),align='center')
        p.penup()
        p.forward(40)
        p.pendown()
    goto_pos(-500,-275)
    for x in text[1][0]:
        p.write(x,font=('宋体',20),align='center')
        p.penup()
        p.forward(25)
        p.pendown()
    goto_pos(-500,-325)
    for x in text[1][1]:
        p.write(x,font=('宋体',20),align='center')
        p.penup()
        p.forward(25)
        p.pendown()
    goto_pos(300,-275)
    for x in text[2][0]:
        p.write(x,font=('宋体',20),align='center')
        p.penup()
        p.forward(25)
        p.pendown()
    goto_pos(300,-325)
    for x in text[2][1]:
        p.write(x,font=('宋体',20),align='center')
        p.penup()
        p.forward(25)
        p.pendown()
    #航天员
    goto_pos(-550,-75,turtle)
    turtle.speed(1)
    turtle.shape('astronaut2.gif')
    turtle.showturtle()
    for x in range(3):
        goto_pos(550,-75,turtle)
        turtle.shape("astronaut.gif")
        goto_pos(-550,-75,turtle)
        turtle.shape('astronaut2.gif')
    turtle.shape('astronaut2.gif')
    goto_pos(2000,-75,turtle)
    turtle.done()
else:
    easygui.msgbox('好吧,下次再阅读吧。再见!','待会儿读','好的,再见!')
    turtle.done()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页