我已经用python用Pygame制作了一个绘画程序,当我使用Pyinstaller将它变成.exe时,它可以工作,但是.exe无法运行,它只是弹出一个黑色的Pygame屏幕,并说它没有响应。我环顾四周,但找不到解决方案。我不知道为什么它不起作用,我已经运行了程序并且可以正常工作,但是.exe无法起作用,它没有图像或声音,因此没有外部声音。这是我的代码:
import pygame
pygame.init()
active = False
running = True
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
screen.fill([0,0,0])
pygame.display.flip()
CS = 1
COLERC = 1
w, h = pygame.display.get_surface().get_size()
w2 = w-120
h2 = h-120
color_inactive = [100,100,100]
color_active = [255,0,0]
color = color_inactive
text = ''
font = pygame.font.Font(None, 60)
label1 = font.render("S", 100,(0,0,0))
label2 = font.render("E", 100,(0,0,0))
label3 = font.render("+", 10000,(255,255,255))
label4 = font.render("-", 10000,(255,255,255))
label5 = font.render("F", 10000,(0,0,0))
WIN = pygame.draw.rect(screen, [255,255,255], (60,60, w2,h2))
SBU = pygame.draw.rect(screen, [70,70,70], (60,0,50,50))
MBU = pygame.draw.rect(screen, [70,70,70], (120,0,50,50))
BBU = pygame.draw.rect(screen, [70,70,70], (180,0,50,50))
CBU = pygame.draw.rect(screen, [70,70,70], (240,0,50,50))
input_box = pygame.Rect(490, 0, 140, 49)
SBUTTON = [pygame.draw.rect(screen, [70,70,70], (60,0,50,50)),
pygame.draw.circle(screen, [255,255,255],(85, 25), 2)]
MBUTTON = [pygame.draw.rect(screen, [70,70,70], (120,0,50,50)),
pygame.draw.circle(screen, [255,255,255],(145, 25), 5)]
BBUTTON = [pygame.draw.rect(screen, [70,70,70], (180,0,50,50)),
pygame.draw.circle(screen, [255,255,255],(205, 25), 10)]
CBUTTON = [pygame.draw.rect(screen, [70,70,70], (240,0,50,50)),
pygame.draw.circle(screen, [255,255,255],(265, 25), 20)]
SAVEBUTTON = pygame.draw.rect(screen,[255,0,0],(430,0,50,50))
ERABUTTON = pygame.draw.rect(screen, [255,0,0],(300,0,50,50))
FSCREENB = pygame.draw.rect(screen, [255,0,0],(565,0,50,50))
r1 = 255
b1 = 0
g1 = 0
CB1 = pygame.draw.rect(screen, [r1,g1,b1],(0,0,50,50))
r2 = 0
b2 = 0
g2 = 255
CB2 = pygame.draw.rect(screen, [r2,g2,b2],(0,60,50,50))
r3 = 0
b3 = 255
g3 = 0
CB3 = pygame.draw.rect(screen, [r3,g3,b3],(0,120,50,50))
GBB = pygame.draw.rect(screen, [0,255,0],(w - 50, 0,50,50))
BBB = pygame.draw.rect(screen, [0,0,255],(w - 50, 60,50,50))
RBB = pygame.draw.rect(screen, [255,0,0],(w - 50, 120,50,50))
WIN
pygame.display.flip()
S = "MEDIUM"
XX = 1
E = False
HIDE = True
while running:
if HIDE == False:
pygame.draw.rect(screen,[r,g,b],(0,0,50,50))
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if active:
if event.key == pygame.K_RETURN:
pygame.draw.rect(screen, [0,0,0], (0,0, 60,h))
pygame.draw.rect(screen, [0,0,0], (0,0, w,60))
pygame.draw.rect(screen, [0,0,0], (w-60,0, 60,h))
pygame.draw.rect(screen, [0,0,0], (0,h-60, w,60))
pygame.image.save(screen, text+".jpeg")
pygame.quit()
elif event.key == pygame.K_BACKSPACE:
text = text[:-1]
else:
text += event.unicode
if event.key == pygame.K_SPACE and active == False:
pygame.draw.rect(screen, [255,255,255], (60,60, w2,h2))
pygame.display.flip()
if event.key == pygame.K_ESCAPE:
pygame.quit()
running = False
if event.type == pygame.MOUSEBUTTONDOWN:
D = True
x, y = event.pos
if SAVEBUTTON.collidepoint(x,y):
active = not active
else:
active = False
if ERABUTTON.collidepoint(x,y):
if XX == 1:
E = True
XX += 1
elif XX == 2:
E = False
XX -= 1
if pygame.draw.rect(screen,[255,255,255],(w - 51,240,50,50),3).collidepoint(x,y):
COLERC = 2
if pygame.draw.rect(screen,[255,255,255],(w - 51,180,50,50),3).collidepoint(x,y):
COLERC = 1
if CB1.collidepoint(x,y):
CS = 1
if CB2.collidepoint(x,y):
CS = 2
if CB3.collidepoint(x,y):
CS = 3
if SBU.collidepoint(x,y):
S = "SMALL"
if MBU.collidepoint(x,y):
S = "MEDIUM"
if BBU.collidepoint(x,y):
S = "BIG"
if CBU.collidepoint(x,y):
S = "COLOSSAL"
if FSCREENB.collidepoint(x,y):
if CS == 1:
pygame.draw.rect(screen, [r1,g1,b1], (60,60, w2,h2))
if CS == 2:
pygame.draw.rect(screen, [r2,g2,b2], (60,60, w2,h2))
if CS == 3:
pygame.draw.rect(screen, [r3,g3,b3], (60,60, w2,h2))
while D == True:
x, y = event.pos
if GBB.collidepoint(x,y) and COLERC == 1:
if CS == 1:
g1 = g1 + 1
if g1 >= 255:
g1 = g1 - 1
CB1 = pygame.draw.rect(screen, [r1,g1,b1],(0,0,50,50))
CB2 = pygame.draw.rect(screen, [r2,g2,b2],(0,60,50,50))
CB3 = pygame.draw.rect(screen, [r3,g3,b3],(0,120,50,50))
pygame.display.flip()
if CS == 2:
g2 = g2 + 1
if g2 >= 255:
g2 = g2 - 1
CB1 = pygame.draw.rect(screen, [r1,g1,b1],(0,0,50,50))
CB2 = pygame.draw.rect(screen, [r2,g2,b2],(0,60,50,50))
CB3 = pygame.draw.rect(screen, [r3,g3,b3],(0,120,50,50))
pygame.display.flip()
if CS == 3:
g3 = g3 + 1
if g3 >= 255:
g3 = g3 - 1
CB1 = pygame.draw.rect(screen, [r1,g1,b1],(0,0,50,50))
CB2 = pygame.draw.rect(screen, [r2,g2,b2],(0,60,50,50))
CB3 = pygame.draw.rect(screen, [r3,g3,b3],(0,120,50,50))
pygame.display.flip()
if GBB.collidepoint(x,y) and COLERC == 2:
if CS == 1:
g1 = g1 - 1
if g1 <= 0:
g1 = g1 + 1
CB1 = pygame.draw.rect(screen, [r1,g1,b1],(0,0,50,50))
CB2 = pygame.draw.rect(screen, [r2,g2,b2],(0,60,50,50))
CB3 = pygame.draw.rect(screen, [r3,g3,b3],(0,120,50,50))
pygame.display.flip()
if CS == 2:
g2 = g2 - 1
if g2 <= 0:
g2 = g2 + 1
CB1 = pygame.draw.rect(screen, [r1,g1,b1],(0,0,50,50))
CB2 = pygame.draw.rect(screen, [r2,g2,b2],(0,60,50,50))
CB3 = pygame.draw.rect(screen, [r3,g3,b3],(0,120,50,50))
pygame.display.flip()
if CS == 3:
g3 = g3 - 1
if g3 <= 0:
g3 = g3 + 1
CB1 = pygame.draw.rect(screen, [r1,g1,b1],(0,0,50,50))
CB2 = pygame.draw.rect(screen, [r2,g2,b2],(0,60,50,50))
CB3 = pygame.draw.rect(screen, [r3,g3,b3],(0,120,50,50))
pygame.display.flip()
if BBB.collidepoint(x,y) and COLERC==1:
if CS == 1:
b1 = b1 + 1
if b1 >= 255:
b1 = b1 - 1
CB1 = pygame.draw.rect(screen, [r1,g1,b1],(0,0,50,50))
CB2 = pygame.draw.rect(screen, [r2,g2,b2],(0,60,50,50))
CB3 = pygame.draw.rect(screen, [r3,g3,b3],(0,120,50,50))
pygame.display.flip()
if CS == 2:
b2 = b2 + 1
if b2 >= 255:
b2 = b2 - 1
CB1 = pygame.draw.rect(screen, [r1,g1,b1],(0,0,50,50))
CB2 = pygame.draw.rect(screen, [r2,g2,b2],(0,60,50,50))
CB3 = pygame.draw.rect(screen, [r3,g3,b3],(0,120,50,50))
pygame.display.flip()
if CS == 3:
b3 = b3 + 1
if b3 >= 255:
b3 = b3 - 1
CB1 = pygame.draw.rect(screen, [r1,g1,b1],(0,0,50,50))
CB2 = pygame.draw.rect(screen, [r2,g2,b2],(0,60,50,50))
CB3 = pygame.draw.rect(screen, [r3,g3,b3],(0,120,50,50))
pygame.display.flip()
if BBB.collidepoint(x,y) and COLERC==2:
if CS == 1:
b1 = b1 - 1
if b1 <= 0:
b1 = b1 + 1
CB1 = pygame.draw.rect(screen, [r1,g1,b1],(0,0,50,50))
CB2 = pygame.draw.rect(screen, [r2,g2,b2],(0,60,50,50))
CB3 = pygame.draw.rect(screen, [r3,g3,b3],(0,120,50,50))
pygame.display.flip()
if CS == 2:
b2 = b2 - 1
if b2 <= 0:
b2 = b2 + 1
CB1 = pygame.draw.rect(screen, [r1,g1,b1],(0,0,50,50))
CB2 = pygame.draw.rect(screen, [r2,g2,b2],(0,60,50,50))
CB3 = pygame.draw.rect(screen, [r3,g3,b3],(0,120,50,50))
pygame.display.flip()
if CS == 3:
b3 = b3 - 1
if b3 <= 0:
b3 = b3 + 1
CB1 = pygame.draw.rect(screen, [r1,g1,b1],(0,0,50,50))
CB2 = pygame.draw.rect(screen, [r2,g2,b2],(0,60,50,50))
CB3 = pygame.draw.rect(screen, [r3,g3,b3],(0,120,50,50))
pygame.display.flip()
if RBB.collidepoint(x,y) and COLERC==1:
if CS == 1:
r1 = r1 + 1
if r1 >= 255:
r1 = r1 - 1
CB1 = pygame.draw.rect(screen, [r1,g1,b1],(0,0,50,50))
CB2 = pygame.draw.rect(screen, [r2,g2,b2],(0,60,50,50))
CB3 = pygame.draw.rect(screen, [r3,g3,b3],(0,120,50,50))
pygame.display.flip()
if CS == 2:
r2 = r2 + 1
if r2 >= 255:
r2 = r2 - 1
CB1 = pygame.draw.rect(screen, [r1,g1,b1],(0,0,50,50))
CB2 = pygame.draw.rect(screen, [r2,g2,b2],(0,60,50,50))
CB3 = pygame.draw.rect(screen, [r3,g3,b3],(0,120,50,50))
pygame.display.flip()
if CS == 3:
r3 = r3 + 1
if r3 >= 255:
r3 = r3 - 1
CB1 = pygame.draw.rect(screen, [r1,g1,b1],(0,0,50,50))
CB2 = pygame.draw.rect(screen, [r2,g2,b2],(0,60,50,50))
CB3 = pygame.draw.rect(screen, [r3,g3,b3],(0,120,50,50))
pygame.display.flip()
if RBB.collidepoint(x,y) and COLERC==2:
if CS == 1:
r1 = r1 - 1
if r1 <= 0:
r1 = r1 + 1
CB1 = pygame.draw.rect(screen, [r1,g1,b1],(0,0,50,50))
CB2 = pygame.draw.rect(screen, [r2,g2,b2],(0,60,50,50))
CB3 = pygame.draw.rect(screen, [r3,g3,b3],(0,120,50,50))
pygame.display.flip()
if CS == 2:
r2 = r2 - 1
if r2 <= 0:
r2 = r2 + 1
CB1 = pygame.draw.rect(screen, [r1,g1,b1],(0,0,50,50))
CB2 = pygame.draw.rect(screen, [r2,g2,b2],(0,60,50,50))
CB3 = pygame.draw.rect(screen, [r3,g3,b3],(0,120,50,50))
pygame.display.flip()
if CS == 3:
r3 = r3 - 1
if r3 <= 0:
r3 = r3 + 1
CB1 = pygame.draw.rect(screen, [r1,g1,b1],(0,0,50,50))
CB2 = pygame.draw.rect(screen, [r2,g2,b2],(0,60,50,50))
CB3 = pygame.draw.rect(screen, [r3,g3,b3],(0,120,50,50))
pygame.display.flip()
color = color_active if active else color_inactive
if CS == 1 and x > 60 and x < w - 60 and y > 60 and y < h - 60:
if S == "SMALL":
pygame.draw.circle(screen, [r1,g1,b1], [x,y], 2)
if E == True:
pygame.draw.circle(screen, [255,255,255], [x,y], 2)
if S == "MEDIUM":
pygame.draw.circle(screen, [r1,g1,b1], [x,y], 5)
if E == True:
pygame.draw.circle(screen, [255,255,255], [x,y], 5)
if S == "BIG":
pygame.draw.circle(screen, [r1,g1,b1], [x,y], 10)
if E == True:
pygame.draw.circle(screen, [255,255,255], [x,y], 10)
if S == "HUGE":
pygame.draw.circle(screen, [r1,g1,b1], [x,y], 20)
if E == True:
pygame.draw.circle(screen, [255,255,255], [x,y], 20)
if S == "COLOSSAL":
pygame.draw.circle(screen, [r1,g1,b1], [x,y], 50)
if E == True:
pygame.draw.circle(screen, [255,255,255], [x,y], 50)
if CS == 2 and x > 60 and x < w - 60 and y > 60 and y < h - 60:
if S == "SMALL":
pygame.draw.circle(screen, [r2,g2,b2], [x,y], 2)
if E == True:
pygame.draw.circle(screen, [255,255,255], [x,y], 2)
if S == "MEDIUM":
pygame.draw.circle(screen, [r2,g2,b2], [x,y], 5)
if E == True:
pygame.draw.circle(screen, [255,255,255], [x,y], 5)
if S == "BIG":
pygame.draw.circle(screen, [r2,g2,b2], [x,y], 10)
if E == True:
pygame.draw.circle(screen, [255,255,255], [x,y], 10)
if S == "HUGE":
pygame.draw.circle(screen, [r2,g2,b2], [x,y], 20)
if E == True:
pygame.draw.circle(screen, [255,255,255], [x,y], 20)
if S == "COLOSSAL":
pygame.draw.circle(screen, [r2,g2,b2], [x,y], 50)
if E == True:
pygame.draw.circle(screen, [255,255,255], [x,y], 50)
if CS == 3 and x > 60 and x < w - 60 and y > 60 and y < h - 60:
if S == "SMALL":
pygame.draw.circle(screen, [r3,g3,b3], [x,y], 2)
if E == True:
pygame.draw.circle(screen, [255,255,255], [x,y], 2)
if S == "MEDIUM":
pygame.draw.circle(screen, [r3,g3,b3], [x,y], 5)
if E == True:
pygame.draw.circle(screen, [255,255,255], [x,y], 5)
if S == "BIG":
pygame.draw.circle(screen, [r3,g3,b3], [x,y], 10)
if E == True:
pygame.draw.circle(screen, [255,255,255], [x,y], 10)
if S == "HUGE":
pygame.draw.circle(screen, [r3,g3,b3], [x,y], 20)
if E == True:
pygame.draw.circle(screen, [255,255,255], [x,y], 20)
if S == "COLOSSAL":
pygame.draw.circle(screen, [r3,g3,b3], [x,y], 50)
if E == True:
pygame.draw.circle(screen, [255,255,255], [x,y], 50)
pygame.draw.rect(screen, [0,0,0], (0,0, 60,h))
pygame.draw.rect(screen, [0,0,0], (0,0, w,60))
pygame.draw.rect(screen, [0,0,0], (w-60,0, 60,h))
pygame.draw.rect(screen, [0,0,0], (0,h-60, w,60))
SBUTTON = [pygame.draw.rect(screen, [70,70,70], (60,0,50,50)),
pygame.draw.circle(screen, [255,255,255],(85, 25), 2)]
MBUTTON = [pygame.draw.rect(screen, [70,70,70], (120,0,50,50)),
pygame.draw.circle(screen, [255,255,255],(145, 25), 5)]
BBUTTON = [pygame.draw.rect(screen, [70,70,70], (180,0,50,50)),
pygame.draw.circle(screen, [255,255,255],(205, 25), 10)]
CBUTTON = [pygame.draw.rect(screen, [70,70,70], (240,0,50,50)),
pygame.draw.circle(screen, [255,255,255],(265, 25), 20)]
SAVEBUTTON = pygame.draw.rect(screen,[255,0,0],(420,0,50,50))
ERABUTTON = pygame.draw.rect(screen, [255,0,0],(300,0,50,50))
FSCREENB = pygame.draw.rect(screen, [255,0,0],(360,0,50,50))
SBUTTON
MBUTTON
BBUTTON
CBUTTON
CB1 = pygame.draw.rect(screen, [r1,g1,b1],(0,0,50,50))
CB2 = pygame.draw.rect(screen, [r2,g2,b2],(0,60,50,50))
CB3 = pygame.draw.rect(screen, [r3,g3,b3],(0,120,50,50))
txt_surface = font.render(text, True, color)
width = max(200, txt_surface.get_width()+10)
input_box.w = width
screen.blit(txt_surface, (input_box.x+5, input_box.y+5))
pygame.draw.rect(screen, color, input_box, 2)
screen.blit(label1, (430, 5))
screen.blit(label2, (310, 5))
screen.blit(label3, (w - 40, 182))
screen.blit(label4, (w - 33, 245))
screen.blit(label5, (370, 5))
if COLERC == 1:
pygame.draw.rect(screen,[255,255,255],(w - 51,180,50,50),3)
if COLERC == 2:
pygame.draw.rect(screen,[255,255,255],(w - 51,240,50,50),3)
if S == "SMALL":
pygame.draw.rect(screen,[255,255,255],(60,0,50,50),3)
if S == "MEDIUM":
pygame.draw.rect(screen,[255,255,255],(120,0,50,50),3)
if S == "BIG":
pygame.draw.rect(screen,[255,255,255],(180,0,50,50),3)
if S == "COLOSSAL":
pygame.draw.rect(screen,[255,255,255],(240,0,50,50),3)
if E == True:
pygame.draw.rect(screen,[255,255,255],(300,0,50,50),3)
if active:
pygame.draw.rect(screen,[255,255,255],(420,0,50,50),3)
GBB = pygame.draw.rect(screen, [0,255,0],(w - 50, 0,50,50))
BBB = pygame.draw.rect(screen, [0,0,255],(w - 50, 60,50,50))
RBB = pygame.draw.rect(screen, [255,0,0],(w - 50, 120,50,50))
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONUP:
D = False
pygame.draw.rect(screen, [0,0,0], (0,0, 60,h))
pygame.draw.rect(screen, [0,0,0], (0,0, w,60))
pygame.draw.rect(screen, [0,0,0], (w-60,0, 60,h))
pygame.draw.rect(screen, [0,0,0], (0,h-60, w,60))
txt_surface = font.render(text, True, color)
width = max(200, txt_surface.get_width()+10)
input_box.w = width
screen.blit(txt_surface, (input_box.x+5, input_box.y+5))
pygame.draw.rect(screen, color, input_box, 2)
SBUTTON = [pygame.draw.rect(screen, [70,70,70], (60,0,50,50)),
pygame.draw.circle(screen, [255,255,255],(85, 25), 2)]
MBUTTON = [pygame.draw.rect(screen, [70,70,70], (120,0,50,50)),
pygame.draw.circle(screen, [255,255,255],(145, 25), 5)]
BBUTTON = [pygame.draw.rect(screen, [70,70,70], (180,0,50,50)),
pygame.draw.circle(screen, [255,255,255],(205, 25), 10)]
CBUTTON = [pygame.draw.rect(screen, [70,70,70], (240,0,50,50)),
pygame.draw.circle(screen, [255,255,255],(265, 25), 20)]
SAVEBUTTON = pygame.draw.rect(screen,[255,0,0],(420,0,50,50))
ERABUTTON = pygame.draw.rect(screen, [255,0,0],(300,0,50,50))
FSCREENB = pygame.draw.rect(screen, [255,0,0],(360,0,50,50))
SBUTTON
MBUTTON
BBUTTON
CBUTTON
GBB = pygame.draw.rect(screen, [0,255,0],(w - 50, 0,50,50))
BBB = pygame.draw.rect(screen, [0,0,255],(w - 50, 60,50,50))
RBB = pygame.draw.rect(screen, [255,0,0],(w - 50, 120,50,50))
CB1 = pygame.draw.rect(screen, [r1,g1,b1],(0,0,50,50))
CB2 = pygame.draw.rect(screen, [r2,g2,b2],(0,60,50,50))
CB3 = pygame.draw.rect(screen, [r3,g3,b3],(0,120,50,50))
screen.blit(label1, (430, 5))
screen.blit(label2, (310, 5))
screen.blit(label3, (w - 40, 182))
screen.blit(label4, (w - 33, 245))
screen.blit(label5, (370, 5))
if COLERC == 1:
pygame.draw.rect(screen,[255,255,255],(w - 51,180,50,50),3)
if COLERC == 2:
pygame.draw.rect(screen,[255,255,255],(w - 51,240,50,50),3)
if S == "SMALL":
pygame.draw.rect(screen,[255,255,255],(60,0,50,50),3)
if S == "MEDIUM":
pygame.draw.rect(screen,[255,255,255],(120,0,50,50),3)
if S == "BIG":
pygame.draw.rect(screen,[255,255,255],(180,0,50,50),3)
if S == "COLOSSAL":
pygame.draw.rect(screen,[255,255,255],(240,0,50,50),3)
if E == True:
pygame.draw.rect(screen,[255,255,255],(300,0,50,50),3)
if active:
pygame.draw.rect(screen,[255,255,255],(420,0,50,50),3)
pygame.display.flip()