一、效果展示
未选中时效果
选中是效果
二、代码
通过on_mouse_move鼠标移动指令配合变量,改变rect矩形的填充色。
import pgzrun
box=Rect((400,300),(100,20))
colors='blue'
def draw():
global colors
screen.fill('white')
screen.draw.filled_rect(box,colors)
screen.draw.text('Start',center=box.center,fontsize=20,color='white')
pass
def on_mouse_move(pos):
global colors
if box.collidepoint(pos):
colors='red'
else:
colors='blue'
pass
def update():
pass
pgzrun.go()