pygame.mouse提供了一些方法获取鼠标设备当前的状态
在下面的demo中,主要用到了:
pygame.mouse.get_pressed()
pygame.mouse.get_pos()
展示的效果:
游戏效果:
当鼠标经过窗口的时候,窗口背景颜色会随着鼠标的移动而发生改变,当鼠标点击窗口
会在控制台打印出是鼠标的那个键被点击了:左,右,滚轮
代码部分:
pygame.locals *
sys random *
= { : : : :
pygame.font:(
screen = pygame.display.set_mode((255,255),32 screen.fill((255,255,255
font = pygame.font.Font(,20 text = font.render(,True,(34,252,43
mouse_x,mouse_y = 1 event event.type == event.type == pressed_array = index index == ( index == 1 ( index == 2 ( event.type ==
pos = mouse_x = mouse_y = pos[1
screen.blit(text,(40,100 pygame.display.update()
========================================================
More reading,and english is important.
I'm Hongten
大哥哥大姐姐,觉得有用打赏点哦!多多少少没关系,一分也是对我的支持和鼓励。谢谢。Hongten博客排名在100名以内。粉丝过千。Hongten出品,必是精品。
E | hongtenzone@foxmail.com B |
========================================================