猫史档案馆


【Python作品分享】【半决赛】【奇遇之旅】长隆海洋生物硬核科普

用户:AristoreAristore查看:0 回复:0 评论:0 创建时间:2021-08-06T11:58:20


【作品展示】

center_image

 

【作品介绍】

首先在右侧选择导游(卡卡,酷酷,萌萌),然后点击右上方按钮查看对应海洋生物介绍。

 

【作品源代码】

from tkinter import *
from PIL import ImageTk
from PIL import Image

app = Tk()

# 更改窗口图标
app.iconbitmap('favicon.ico')

# 设置标题
app.title('长隆海洋生物硬核科普 —— By 对对对你说的都队')

# 设置窗口大小
app.geometry('600x500')

# 设置窗口是否可变长、宽,True:可变,False:不可变
app.resizable(width = False, height = False)

# 设置对话框
def talk(name = '', text = ''):
    lf = LabelFrame(app, font="Helvetica 15 bold", text=name)
    lf.place(x=0, y=400, width=600, height=100)
    ent = Text(lf, width=500, height=60)
    ent.pack()
    ent.insert(END, text)

# 加载图片
def get_img(filename):
    img = Image.open(filename)
    img = ImageTk.PhotoImage(img)
    return img

# 设置背景图片
canvas = Canvas(app, width=600, height=500)
background = get_img("background0.png")
canvas.create_image(300, 200, image = background)
canvas.pack()

# 介绍
name = '帅帅.png'
img_app = get_img(name)
img_labe = Label(app, image=img_app)
img_labe.place(x=0, y=160, width=140, height=240)
talk("帅帅", "你好呀,我是帅帅。下面将由卡卡,酷酷和萌萌为您介绍长隆海洋王国里的海洋生物。\n请点击右侧按钮选择导游")

# 卡卡
def aa1():
    global img_app
    global img_ani
    img_app = get_img('02卡卡.png')
    img_labe = Label(app, image=img_app)
    img_labe.place(x=0, y=160, width=140, height=240)
    img_ani = get_img('白鲸.png')
    img_lani = Label(app, image=img_ani)
    img_lani.place(x=250, y=130, width=200, height=240)
    talk("卡卡", "白鲸,学名:Delphinapterus leucas (Pallas,1776),一角鲸科白鲸属的一种动物。\n额头向外隆起突出且圆滑,嘴喙很短,唇线宽阔。身体颜色非常淡,为独特的白色。白鲸与其他鲸类相比,惟一明显不同的是:当夏季皮肤呈淡黄色的色调时,可以蜕换。")

def aa2():
    global img_app
    global img_ani
    img_app = get_img('03卡卡.png')
    img_labe = Label(app, image=img_app)
    img_labe.place(x=0, y=160, width=140, height=240)
    img_ani = get_img('鲸鲨.png')
    img_lani = Label(app, image=img_ani)
    img_lani.place(x=250, y=130, width=200, height=240)
    talk("卡卡", "鲸鲨,Rhincodon typus (Smith, 1828),鲸鲨科鲸鲨属的鲨鱼。\n鲸鲨仅1科1属1种。身体庞大,全长可达20米,是世界上最大的鱼类。体表散布淡喵点与纵横交错的淡色带,有如棋盘。鼻孔位于上唇的两侧,出现于口内。牙多而细小,排成多行。鳃裂5对,鳃裂极大,几乎达身体的背缘与腹缘,最后1对鳃裂位于胸鳍基部的前方。背鳍2个,无棘,第1背鳍位在腹鳍前方,有臀鳍。尾柄具侧棱,尾鳍呈新月形,下叶短于上叶。如鲸鲨,有二背鳍,大小不同,胸鳍大,位于第三对鳃裂下,腹鳍小,尾鳍叉型,口宽,端位,鳃耙如海绵状。")

def aa3():
    global img_app
    global img_ani
    img_app = get_img('04卡卡.png')
    img_labe = Label(app, image=img_app)
    img_labe.place(x=0, y=160, width=140, height=240)
    img_ani = get_img('海狮.png')
    img_lani = Label(app, image=img_ani)
    img_lani.place(x=250, y=130, width=200, height=240)
    talk("卡卡", "海狮(学名:Otarriinae):包括5属7种。\n分布北半球。体型较小,体长一般不超过2米。北海狮为海狮科最大的一种。雄性体长310-350厘米,体重1000千克以上。雄性成体颈部周围及肩部生有长而粗的鬃毛,体毛为黄褐色,背部毛色较浅,胸及腹部色深。雌性体色比雄兽淡,没有鬃毛。面部短宽,吻部钝,眼和外耳壳较小。前肢较后肢长且宽,前肢第一趾最长,爪退化。后肢的外侧趾较中间三趾长而宽,中间三趾具爪。")

# 酷酷
def bb1():
    global img_app
    global img_ani
    img_app = get_img('02酷酷.png')
    img_labe = Label(app, image=img_app)
    img_labe.place(x=0, y=160, width=140, height=240)
    img_ani = get_img('蝠鲼.png')
    img_lani = Label(app, image=img_ani)
    img_lani.place(x=250, y=130, width=200, height=240)
    talk("酷酷", "蝠鲼(Mobula),又被称为魔鬼鱼与毯魟。属于软骨鱼纲、蝠鲼科,它包含两个属,前口蝠鲼属和蝠鲼属。\n体呈菱形,宽达6m余。体青褐色。口宽大。眼下侧位,能侧视和俯视。头侧有1对有胸鳍分化的头鳍,向前突出。背鳍小,胸鳍翼状。尾细长如鞭,具尾刺。平时底栖生活,但有时上升表层游弋,并做远程洄游,行动敏捷。以浮游甲壳类和小鱼为食。卵胎生。分布于热带和温带各海区,中国见于东海、南海和喵沿海。常见的如日本蝠鲼(Mobula japonica)、双吻前口蝠鲼(Manta birostris)。")

def bb2():
    global img_app
    global img_ani
    img_app = get_img('03酷酷.png')
    img_labe = Label(app, image=img_app)
    img_labe.place(x=0, y=160, width=140, height=240)
    img_ani = get_img('海龟.png')
    img_lani = Label(app, image=img_ani)
    img_lani.place(x=250, y=130, width=200, height=240)
    talk("酷酷", "海龟(学名:Chelonia mydas)是海龟科、海龟属动物。\n头背具对称大鳞,前额鳞一对。上颌平出,下颌略向上钩曲,颚缘有锯齿状缺刻。吻部短圆,上颚前端不成钩曲。背甲呈心形,盾片镶嵌排列;椎盾5枚;肋盾4对,第一对肋盾不与颈盾相接,缘盾每侧11片;喉盾前有单枚问喉盾;背腹甲间有一系列下缘盾。四肢桨状,前肢长于后肢,每肢内侧各具1爪。背甲橄榄色或棕色,杂有黄白色放射纹;背甲橄榄色或棕褐色,杂以浅喵纹;雄陛尾长,达体长的二分之一,前肢的爪强大而弯曲成钩状。")

def bb3():
    global img_app
    global img_ani
    img_app = get_img('04酷酷.png')
    img_labe = Label(app, image=img_app)
    img_labe.place(x=0, y=160, width=140, height=240)
    img_ani = get_img('双髻鲨.png')
    img_lani = Label(app, image=img_ani)
    img_lani.place(x=250, y=130, width=200, height=240)
    talk("酷酷", "双髻鲨又称锤头鲨,是鲨纲、双髻鲨科鱼类的统称。\n双髻鲨以其头部的形状而得名。双髻鲨的头部有左右两个突起。每个突起上各有一只眼睛和一个鼻孔。两只眼睛相距1米。最近的一项研究证实,眼睛的分布对它观察周围情况非常有利。双髻鲨不仅像人类一样拥有双眼视力(两只眼睛的视野重叠在一起),而且它通过来回摇摆脑袋,可以看到周围360度范围内发生的情况。")


# 萌萌
def cc1():
    global img_app
    global img_ani
    img_app = get_img('02萌萌.png')
    img_labe = Label(app, image=img_app)
    img_labe.place(x=0, y=160, width=140, height=240)
    img_ani = get_img('海豚.png')
    img_lani = Label(app, image=img_ani)
    img_lani.place(x=250, y=130, width=200, height=240)
    talk("萌萌", "海豚是对海豚科(学名:Delphinidae)的一类水生哺乳动物的统称,为小型或中型齿鲸。\n广泛生活于世界各大洋,在内海及江河入海口附近的咸淡水中也有分布,个别种类见于内陆河流。通常喜欢群居,捕食鱼类、乌贼等。")

def cc2():
    global img_app
    global img_ani
    img_app = get_img('03萌萌.png')
    img_labe = Label(app, image=img_app)
    img_labe.place(x=0, y=160, width=140, height=240)
    img_ani = get_img('河豚.png')
    img_lani = Label(app, image=img_ani)
    img_lani.place(x=250, y=130, width=200, height=240)
    talk("萌萌", "河豚是河鲀的别称,泛指硬骨鱼纲、鲀形目、鲀科的各属鱼类。\n其肉味鲜美、营养丰富,是一种名贵的高档水产品,被誉为“菜肴之冠”,但其喵、肝脏、肾脏、眼睛、血液中含有剧毒,处理不当或误食,轻者中毒,重者丧命。")

def cc3():
    global img_app
    global img_ani
    img_app = get_img('04萌萌.png')
    img_labe = Label(app, image=img_app)
    img_labe.place(x=0, y=160, width=140, height=240)
    img_ani = get_img('小丑鱼.png')
    img_lani = Label(app, image=img_ani)
    img_lani.place(x=250, y=130, width=200, height=240)
    talk("萌萌", "小丑鱼(学名:Amphiprioninae)是对雀鲷科海葵鱼亚科鱼类的俗称,因为脸上都有一条或两条白色条纹,好似京剧中的丑角而得名,是一种热带咸水鱼。\n已知有28种,一种来自棘颊雀鲷属(Premnas),其余来自双锯鱼属(Amphiprion)。小丑鱼与海葵有着密不可分的共生关系,因此又称海葵鱼。")

# 转换
def changemeng():
    global img_app
    img_app = get_img('01萌萌.png')
    img_labe = Label(app, image=img_app)
    img_labe.place(x=0, y=160, width=140, height=240)
    talk("萌萌", "你好呀,我是萌萌。接下来轮到我为您介绍长隆海洋王国里的海洋生物。请点击右侧按钮查看")

    Button(app, text="海豚", command=cc1).place(x=500, y=0, height=30, width=100)
    Button(app, text="河豚", command=cc2).place(x=500, y=30, height=30, width=100)
    Button(app, text="小丑鱼", command=cc3).place(x=500, y=60, height=30, width=100)

def changeku():
    global img_app
    img_app = get_img('01酷酷.png')
    img_labe = Label(app, image=img_app)
    img_labe.place(x=0, y=160, width=140, height=240)
    talk("酷酷", "你好呀,我是酷酷。接下来轮到我为您介绍长隆海洋王国里的海洋生物。请点击右侧按钮查看")

    Button(app, text="蝠鲼", command=bb1).place(x=500, y=0, height=30, width=100)
    Button(app, text="海龟", command=bb2).place(x=500, y=30, height=30, width=100)
    Button(app, text="双髻鲨", command=bb3).place(x=500, y=60, height=30, width=100)

def changeka():
    global img_app
    img_app = get_img('01卡卡.png')
    img_labe = Label(app, image=img_app)
    img_labe.place(x=0, y=160, width=140, height=240)
    talk("卡卡", "你好呀,我是卡卡。接下来轮到我为您介绍长隆海洋王国里的海洋生物。请点击右侧按钮查看")

    Button(app, text="白鲸", command=aa1).place(x=500, y=0, height=30, width=100)
    Button(app, text="鲸鲨", command=aa2).place(x=500, y=30, height=30, width=100)
    Button(app, text="海狮", command=aa3).place(x=500, y=60, height=30, width=100)

#切换按钮
Button(app, text="萌萌", command=changemeng).place(x=500, y=200, height=30, width=100)
Button(app, text="卡卡", command=changeka).place(x=500, y=230, height=30, width=100)
Button(app, text="酷酷", command=changeku).place(x=500, y=260, height=30, width=100)


app.mainloop()

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页