孙悟空的72变_Python创意编程_Turtle创意编程

配合着西游记音乐的锣鼓声,孙悟空会说他有72变,单击鼠标,它会变身!>

"""孙悟空的72变_Python创意编程_Turtle创意编程"""

from turtle import *
from time import sleep
from random import choice
from tkinter import messagebox
from winsound import PlaySound,SND_ASYNC,SND_LOOP

screen = Screen()
screen.bgpic("背景2.gif")
screen.title("孙悟空的72变by lixingqiu")
screen.setup(480,360)                         # 设定屏幕分辨率

sprites = ["阿童木.gif","光头强.gif","灰太狼.gif","斑马.gif","机器猫.gif","猫.gif","外星人.gif","小猫.gif"]

[screen.addshape(item) for item in sprites]   # 注册gif图形
    
screen.addshape("孙悟空.gif")                 # 这个形状不要在'sprites'里,这样孙悟空就不会变回来
 
sunwukong = Turtle(shape="孙悟空.gif")        # 新建海龟对象

sleep(1)

messagebox.showinfo("Hi,", "我是孙悟空,大家都知道我有72变")
messagebox.showinfo("大家好", "请单击鼠标让我变身!")
 
screen.onclick(lambda x,y:sunwukong.shape(choice(sprites))) # 单击屏幕,从sprites列表中随机选择一张图片

music = "西游记片头曲敲鼓.wav"
 
PlaySound(music,SND_ASYNC|SND_LOOP)
       
screen.mainloop()