【发布时间】:2020-08-16 18:16:23
【问题描述】:
我有一些使用 pygame 创建按钮的代码。按下此按钮时,将打开一个 pysimplegui 窗口。当这个 pysimplegui 窗口关闭时,它不能再次重新打开。我想知道是否有某种方法可以重新打开窗口。
pygame 按钮的代码:
def button(msg,x,y,w,h,ic,ac,action =None):
if x + y > mouse[0] > x and y + h > mouse[1] > y:
pygame.draw.rect(gameDisplay, ac,(x,y,w,h))
if click[0] == 1 and action!= None:
if action == "play":
asdc(window)
if action == "quit":
pygame.quit()
quit()
else:
pygame.draw.rect(gameDisplay, ic,(x,y,w,h))
smallText = pygame.font.SysFont("comicsansms",20)
textSurf, textRect = text_objects(msg, smallText)
textRect.center = ((round(x+(w/2))), (round(y + (h/2))))
gameDisplay.blit(textSurf, textRect)
pysimplegui 按钮的代码:
def asdc(window):
while True:
event, values = window.Read()
if event == sg.WIN_CLOSED:
break
if event == 'Enter':
event, values = window.Read()
AllyBan1 = values["AllyBan1"]
AllyBan2 = values["AllyBan2"]
AllyBan3 = values["AllyBan3"]
AllyBan4 = values["AllyBan4"]
AllyBan5 = values["AllyBan5"]
break
window.close()
代码是如何运行的:
while True:
gameDisplay.fill(white)
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
button("Enter",100,150,100,50,darkgreen,green,"play")
button("Exit",450,150,100,50,darkred,red,"quit")
for event in pygame.event.get() :
if event.type == pygame.QUIT :
pygame.quit()
quit()
pygame.display.update()
提前致谢
【问题讨论】:
标签: python pygame pysimplegui