
Python的界面模块基本上有Pygame 和 tkinter 两种
这里先讲pygame
#Pygame
Pygame 模块的优势是“方便运动”
1.初始化:
a=0
b=0
def canvasInit(image):
a=a+1
canvas.blit(image,(a,b))
pygame.display.update()
2.主循环
#主循环
while True:
title = '##'
canvasInit(title)
#导入图片
bg = pygame.image.load('images1/bg.jpg')
canvas.blit(bg,(0,0))
pygame.display.update()
#要注意:1.除初始化之外,pygame的所有代码都要写在while True里;
2.记得用pyame.display.update()来刷新;
3.事件
#事件
for event in pygame.event.get():
#鼠标点击事件
if event.type == pygame.MOUSEBUTTONDOWN:
#鼠标左键点击
if event.button == 1:
#获取鼠标位置
pos = pygame.mouse.get_pos()
msx = pos[0]
msy = pos[1]
#具体判断
if 500 <= msx <= 753 and 580 <= msy <=660:
pygame.quit()
#event(pygame.event.get)可以获取当前事件(如鼠标被按下)
4.动起来!!
a = 0
b = 350
def waiter(image):
global a, b, c
if a >= 314:
a = 0
canvas.blit(image,(a,b))
a += 10
这里的image形参是一个用pygame.images.load()传进来的图片
效果就是可以让一个图片从左往右运动直到x坐标=314的时候
#a是x坐标,b是y坐标
4171

被折叠的 条评论
为什么被折叠?



