"""
一闪一闪亮晶晶.py
本程序采用海龟盖图章的方式,让100颗星星不断地闪烁。
读者可能知道在Python海龟画图中可以让海龟盖图章,盖的图章不能动,也不能换造型。
难道这一切都是真的,如果你熟知tkinter,那么一切迎刃而解。
这个程序,只有一个隐藏的海龟,所有的星星都是动态的“图章”。
"""
from time import sleep
from PIL import Image,ImageTk
from turtle import Turtle,Screen
from random import randint,choice
from winsound import PlaySound,SND_LOOP,SND_ASYNC
screen = Screen()
screen.setup(800,600)
screen.title("一闪一闪亮晶晶by李兴球")
screen.delay(0)
screen.bgpic("bg2.png")
# 异步重复播放音乐
PlaySound('一闪一闪亮晶晶伴奏.wav',SND_LOOP|SND_ASYNC)
images = ["star1.gif","star2.gif"]
images = [Image.open(im) for im in images] # 打开每张图到内存
images = [ImageTk.PhotoImage(im) for im in images]# 用PhotoImage包装每张图
star = Turtle(shape='blank') # 实例化空白图形的海龟
star.penup() # 抬笔
star.speed(0) # 速度为最快
for _ in range(100): # 重复100次
x = randint(-400,400) # 设定x的值
y = randint(-300,300) # 设定y的值
star.goto(x,y) # 到达x,y坐标
star.stamp() # 盖图章
print(star.stampItems) # 打印所有图章id
# 接下来的代码让每个图章不断地闪烁,即变换造型图片
pass # 这里省略了部分代码
需要完整源代码请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)

