所以我正在使用 python 2.7.3 和 1.9.1 或 1.9.2,我正在制作一个小应用程序,您可以在其中绘制和更改颜色并保存。只有一个大问题。我先给你看代码(完整代码)
import sys, pygame
from pygame import *
pygame.init()
size = 500, 500
screen = pygame.display.set_mode(size)
screen.fill((255,255,255))
brush = pygame.image.load("C:\Users\Pygame draw\\black1.png")
pygame.display.set_caption("THE EPIC DRAWING THING...")
clock = pygame.time.Clock()
black = pygame.image.load("C:\Users\Pygame draw\\black.png")
white = pygame.image.load("C:\Users\Pygame draw\white.png")
blue = pygame.image.load("C:\Users\Pygame draw\\blue.png")
brown = pygame.image.load("C:\Users\Pygame draw\\brown.png")
green = pygame.image.load("C:\Users\Pygame draw\green.png")
light_blue = pygame.image.load("C:\Users\Pygame draw\light blue.png")
pink = pygame.image.load("C:\Users\Pygame draw\pink.png")
purple =pygame.image.load("C:\Users\Pygame draw\purple.png")
red = pygame.image.load("C:\Users\Pygame draw\\red.png")
save = pygame.image.load("C:\Users\Pygame draw\save drawing.png")
exit = pygame.image.load("C:\Users\Pygame draw\exit.png")
black1 = pygame.image.load("C:\Users2\Pygame draw\\black1.png")
white1 = pygame.image.load("C:\Users\Pygame draw\white1.png")
blue1 = pygame.image.load("C:\Users\Pygame draw\\blue1.png")
brown1 = pygame.image.load("C:\Users\Pygame draw\\brown1.png")
green1 = pygame.image.load("C:\Users\Pygame draw\green1.png")
light_blue1 = pygame.image.load("C:\Users\Pygame draw\light blue1.png")
pink1 = pygame.image.load("C:\Users\Pygame draw\pink1.png")
purple1 =pygame.image.load("C:\Users\Pygame draw\purple1.png")
red1 = pygame.image.load("C:\Users\Pygame draw\\red1.png")
z = 0
while 1:
clock.tick(60)
mx,my = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == pygame.QUIT:sys.exit()
elif event.type == KEYDOWN and event.key == K_ESCAPE:sys.exit()
elif event.type == MOUSEBUTTONDOWN and pygame.mouse.get_pressed(): z = 1
elif event.type == MOUSEBUTTONUP: z = 0
if z == 1:
screen.blit(brush,(mx-5,my-5))
screen.blit(black,(0,0))
screen.blit(brown,(21,0))
screen.blit(purple,(42,0))
screen.blit(blue,(63,0))
screen.blit(light_blue,(84,0))
screen.blit(green,(105,0))
screen.blit(red,(126,0))
screen.blit(pink,(148,0))
screen.blit(white,(169,0))
screen.blit(save,(207,0))
screen.blit(exit,(430,0))
pygame.display.update()
所以基本上,我希望它是这样的,如果我,比如说,点击图片“红色”,画笔变成“red1”,这是我唯一需要帮助的事情,我可以改变画笔颜色,但我只需要它这样如果我单击其中一个,我可以更改画笔颜色谢谢 :) ps 我使用 eclipse 作为 IDE