pygzun库的使用比pygame简洁很多,编程逻辑还是不够灵活,比较固化。
import pgzrun,time
#设置窗口大小
WIDTH=480
HEIGHT=600
button = Actor(“up”, topleft=(150, 200))
count=1
time=0
def draw():
screen.fill(“lightblue”)
button.draw()
if count ==1:
screen.draw.text(“Time:{:.2f}”.format(time),color=“white”,topleft=(180,100),fontsize=50)
def update_time():
global time,count
if count==0:
time+=0.01
def on_mouse_down(pos):
global count,time
if count==1:
if button.collidepoint(pos):
button.image=“down”
count-=1
time=0
clock.schedule_interval(update_time,0.01)
def on_mouse_up():
global count
count=1
button.image=“up”
pgzrun.go()