[英]Why does my python/pygame application not pop up properly
我已经用python和pygame制作了一个程序,并使用py2app将其捆绑到一个.app文件中。 当我单击图标时,它只是无法正确打开,直到我单击扩展坞上的图标时,它才出现在屏幕上,此时,某些代码已经运行,并且破坏了实际程序的作用。
我也似乎无法将图标从普通图标更改为我制作的图标,我已将其放入文件夹中,替换了默认图标。 图标没有出现在底座上,而pygame蛇出现了。
最终.app文件将在任何Mac上运行吗?
顺便说一句,这只是一些有趣代码的程序:
import random, pygame, time, sys
time.sleep(2)
colour_1 = (0,255,255)
colour_2 = (0,255,0)
colour_3 = (255,255,0)
colour_4 = (255,0,0)
colour_5 = (0,0,255)
black = (0,0,0)
white = (255,255,255)
h = 500
w = 500
pygame.init()
FPS = 30
fpsClock = pygame.time.Clock()
screen = pygame.display.set_mode((w,h))
pygame.display.set_caption("You just lost the game")
alpha = 255
shape = screen.convert_alpha()
stimulus = pygame.Rect(0,0,500,500)
def the_game():
#Makes the text "the game" and the text "you just lost it" fade into the screen
global alpha
alpha = alpha - 5
##############
Font = pygame.font.SysFont("monospace",40,True,False)
Text = Font.render("The Game",1,white)
screen.blit(Text,(140,125))
pygame.draw.rect(shape,(0,0,0,alpha),stimulus)
screen.blit(shape,(0,0))
pygame.display.update(stimulus)
fpsClock.tick(FPS)
def lost_it():
#Writes "the game" and "you just lost it" onto the screen
Font = pygame.font.SysFont("monospace",40,True,False)
Text = Font.render("The Game",1,(white))
text = Font.render("YOU JUST LOST IT",1,(white))
screen.blit(text,(50,250))
screen.blit(Text,(140,125))
pygame.display.update()
def flash():
#Writes "the game" and "you just lost it" onto the screen
#Changes the background colour of the screen
Font = pygame.font.SysFont("monospace",40,True,False)
Text = Font.render("The Game",1,(black))
text = Font.render("YOU JUST LOST IT",1,(black))
rand = random.randint(0,5)
if rand == 1:
screen.fill(colour_1)
if rand == 2:
screen.fill(colour_2)
if rand == 3:
screen.fill(colour_3)
if rand == 4:
screen.fill(colour_4)
if rand == 5:
screen.fill(colour_5)
screen.blit(text,(50,250))
screen.blit(Text,(140,125))
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit(); sys.exit();
while True:
if alpha == 0:
break
else:
the_game()
time.sleep(1)
lost_it()
while True:
flash()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit(); sys.exit();
pygame.display中有一个名为set_icon的方法。 您可以使用它来覆盖默认的蛇形图标
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.