gpt4 book ai didi

python - 如何正确实现复位功能?

转载 作者:行者123 更新时间:2023-12-04 15:19:48 28 4
gpt4 key购买 nike

我的 reset() 函数应该清除所有内容并重绘新的内容,但它不起作用。有人可以给我一些建议吗?

import pygame
import string
import random
import time
import sys

pygame.init ()
size = (1600, 900)
win = pygame.display.set_mode(size)
pygame.display.set_caption('Gerador de encontros para Tomb of Annihilation')
win.fill((255,255,255))
pygame.display.update()
red = (200,0,0)
green = (0,200,0)
blue = (0,0,200)
black = (0,0,0)
white = (255,255,255)
encontro1 = "Aguardando"
encontro = 0
MONSTRO_T = "Arakrocra.jpg"
texto = "Monstro Puto"
item = "NONE"
image = pygame.image.load(MONSTRO_T)
imagePos = (1100,190)
win.blit(image, imagePos)
def text_objects(text, font, color):
textSurface = font.render(text, True, color)
return textSurface, textSurface.get_rect()


def button(msg,x,y,w,h,ic,ac,it,at,action=None):
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()


if x+w > mouse[0] > x and y+h > mouse[1] > y:
pygame.draw.rect(win, ac,(x,y,w,h))
smallText = pygame.font.Font("freesansbold.ttf",18)
textSurf, textRect = text_objects(msg, smallText,at)
textRect.center = ( (x+(w/2)), (y+(h/2)) )
win.blit(textSurf, textRect)
if click[0] == 1 and action != None:
action()
else:
pygame.draw.rect(win, ic,(x,y,w,h))
smallText = pygame.font.Font("freesansbold.ttf",20)
textSurf, textRect = text_objects(msg, smallText,it)
textRect.center = ( (x+(w/2)), (y+(h/2)) )
win.blit(textSurf, textRect)
## x = eixoX, y = eixoY, w = Altura, h = Largura, ic = Cor inativa ( do botão ), ac = cor ativa, it = Inative text color, at = active text color
def M_generator():
return (random.randint(1,100))

def ef():
global encontro
global encontro1
encontro = 1
encontro1 = "Characters Level 1 to 4"


def en():
global encontro
global encontro1
encontro = 2
encontro1 = "Characters Level 4 to 8"


def em():
global encontro
global encontro1
encontro = 3
encontro1 = "Characters Level 8 or above"

def warning():
largeText = pygame.font.Font('freesansbold.ttf',50)
TextSurf, TextRect = text_objects('Selecione a dificuldade primeiro', largeText, red)
TextRect.center = ((700),(300))
win.blit(TextSurf, TextRect)
pygame.display.update()

def lore(tf,color,ta,tl,texto):
largeText = pygame.font.Font('freesansbold.ttf',tf)
TextSurf, TextRect = text_objects(texto, largeText, color)
TextRect.center = ((tl),(ta))
win.blit(TextSurf, TextRect)
pygame.display.update()

def quitgame():
pygame.quit()
exit()

def CACHES():
global texto
global item
roll = (random.randint(1,20))
if roll == 1:
texto = "Rain catcher (see chapter l) and mess kit "
item1 = (random.randint(1,100))
item = "1"
elif roll == 2:
texto = "10-day supply of preserved rations"
item1 = (random.randint(1,10))
item = str(item1)
elif roll == 3:
texto = "20-day supply of preserved rations"
item1 = (random.randint(1,20))
item = str(item1)
elif roll == 4:
texto = "50-day supply of preserved rations"
item1 = (random.randint(1,50))
item = str(item1)
elif roll == 5:
texto = "ld4 casks of water holding 5 gallons each"
item1 = (random.randint(1,4))
item = str(item1)
elif roll == 6:
texto = "ld4 casks oftej (see chapter l)"
item1 = (random.randint(1,4))
item = str(item1)
elif roll == 7:
texto = "ld4 climber's kits"
item1 = (random.randint(1,4))
item = str(item1)
elif roll == 8:
texto = "20-day supply of insect repellent salve (see chapter l) in a leather tube"
item1 = (random.randint(1,20))
item = str(item1)
elif roll == 9:
texto = "ld4 quivers, each containing ld20 arrows"
item1 = (random.randint(1,4))
item = str(item1)
elif roll == 10:
texto = "Canoe with six paddles"
item1 = (random.randint(1,100))
item = "1"
elif roll == 11:
texto = "2 hooded lanterns and 10 flasks of lamp oil"
item1 = (random.randint(1,10))
item = str(item1)
elif roll == 12:
texto = "Two-person tent and ld4 explorer's packs"
item1 = (random.randint(1,4))
item = str(item1)
elif roll == 13:
texto = "Wooden box containing 2dl0 daggers (low quality,of the type used as trade goods)"
item1 = (random.randint(2,20))
item = str(item1)
elif roll == 14:
texto = "20-day supply of insect repellent salve (see chapter l) in a leather tube"
item1 = (random.randint(1,20))
item = str(item1)
elif roll == 15:
texto = "Set of navigator's tools"
item1 = (random.randint(1,100))
item = "1"
elif roll == 16:
texto = "ldlO changes of woolen clothing"
item1 = (random.randint(1,10))
item = str(item1)
elif roll == 17:
texto = "Set of cartographer's tools"
item1 = (random.randint(1,100))
item = "1"
elif roll == 18:
texto = "Two-person tent and 1d4 healer's kits"
item1 = (random.randint(1,4))
item = str(item1)
elif roll == 19:
texto = "2 two-person tents, folding camp table, and four folding stools"
item1 = (random.randint(1,100))
item = "1"
else :
texto = "Wooden box containing 2d4 po lions of healing"
item1 = (random.randint(2,8))
item = str(item1)



def beach():
global MONSTRO_T
MONSTRO_N = (M_generator())
if (MONSTRO_N < 7):
if encontro == 1:
MONSTRO_T = "Arakocra.jpg"
imagePos = (900,190)
win.blit(image, imagePos)
lore(30,black,250,500,"Any character with a passive Wisdom (Perception) score ")
lore(30,black,300,500,"of 15 or higher spots ld4 + 1 aarakocra flying overhead. ")
lore(30,black,350,500,"These creatures are scouts from Kir Sabal or another ")
lore(30,black,400,500,"aerie. They observe the party from a safe distance")
lore(30,black,450,500,"but don't approach unless the characters demonstrate")
lore(30,black,500,500,"peaceful intentions. The bird folk are friendly and can")
lore(30,black,550,500,"point characters in the direction of nearby landmarks.")
grupo1 = (random.randint(1,4)+1)
print(grupo1)
grupo = str(grupo1)
lore(35,black,600,500,"Grupo de ")
lore(35,black,600,650,grupo)
if encontro == 2:
MONSTRO_T = "Arakocra.jpg"
imagePos = (900,190)
win.blit(image, imagePos)
lore(30,black,250,500,"Any character with a passive Wisdom (Perception) score ")
lore(30,black,300,500,"of 15 or higher spots 2d4 + 2 aarakocra flying overhead. ")
lore(30,black,350,500,"These creatures are scouts from Kir Sabal or another ")
lore(30,black,400,500,"aerie. They observe the party from a safe distance")
lore(30,black,450,500,"but don't approach unless the characters demonstrate")
lore(30,black,500,500,"peaceful intentions. The bird folk are friendly and can")
lore(30,black,550,500,"point characters in the direction of nearby landmarks.")
grupo1 = (random.randint(2,8)+2)
print(grupo1)
grupo = str(grupo1)
lore(35,black,600,500,"Grupo de ")
lore(35,black,600,650,grupo)
if encontro == 3:
MONSTRO_T = "Arakocra.jpg"
imagePos = (900,190)
win.blit(image, imagePos)
lore(30,black,250,500,"Any character with a passive Wisdom (Perception) score ")
lore(30,black,300,500,"of 15 or higher spots 3d4 + 3 aarakocra flying overhead. ")
lore(30,black,350,500,"These creatures are scouts from Kir Sabal or another ")
lore(30,black,400,500,"aerie. They observe the party from a safe distance")
lore(30,black,450,500,"but don't approach unless the characters demonstrate")
lore(30,black,500,500,"peaceful intentions. The bird folk are friendly and can")
lore(30,black,550,500,"point characters in the direction of nearby landmarks.")
grupo1 = (random.randint(3,12)+3)
print(grupo1)
grupo = str(grupo1)
lore(35,black,600,500,"Grupo de ")
lore(35,black,600,650,grupo)
elif ((MONSTRO_N > 7) and (MONSTRO_N < 10)):
MONSTRO_T = "Cache.jpg"
imagePos = (900,190)
win.blit(image, imagePos)
lore(30,black,250,500,"The party finds a cache of supplies left behind by other")
lore(30,black,300,500,"explorers. There's no way to ten from the cache whether")
lore(30,black,350,500,"those who left it are still alive and coming back for it, or")
lore(30,black,400,500,"dead. Roll a d20 and consult the Caches table to determine what")
lore(30,black,450,500,"the characters find. ")
lore(30,black,500,500,texto)
lore(30,black,500,700,item)

elif ((MONSTRO_N > 10) and (MONSTRO_N < 12)):
MONSTRO_T = "Chwinga.jpg"
elif ((MONSTRO_N > 12) and (MONSTRO_N < 14)):
MONSTRO_T = "Dinossauro, Allosaurus.jpg"
elif ((MONSTRO_N > 14) and (MONSTRO_N < 16)):
MONSTRO_T = "Dinossauro, Dimetrodon.jpg"
elif ((MONSTRO_N > 16) and (MONSTRO_N < 21)):
MONSTRO_T = "Dinossauro, Plesiosaurus.jpg"
elif ((MONSTRO_N > 21) and (MONSTRO_N < 28)):
MONSTRO_T = "Dinossauro, Pteranodon.jpg"
elif ((MONSTRO_N > 28) and (MONSTRO_N < 31)):
MONSTRO_T = "Dinossauro, Quetzalcoatlus.jpg"
elif ((MONSTRO_N > 31) and (MONSTRO_N < 37)):
MONSTRO_T = "Dinossauro, Velociraptor.jpg"
elif ((MONSTRO_N > 37) and (MONSTRO_N < 40)):
MONSTRO_T = "Dragon, Red.jpg"
elif ((MONSTRO_N > 40) and (MONSTRO_N < 42)):
MONSTRO_T = "Emerald Enclave.jpg"
elif ((MONSTRO_N > 42) and (MONSTRO_N < 46)):
MONSTRO_T = "Explorers.jpg"
elif ((MONSTRO_N > 46) and (MONSTRO_N < 49)):
MONSTRO_T = "Flaming Fist.jpg"
elif ((MONSTRO_N > 49) and (MONSTRO_N < 52)):
MONSTRO_T = "Flying Monkeys"
elif ((MONSTRO_N > 52) and (MONSTRO_N < 55)):
MONSTRO_T = "Flying Snakes.jpg"
elif ((MONSTRO_N > 55) and (MONSTRO_N < 57)):
MONSTRO_T = "Frost Giants"
elif ((MONSTRO_N > 57) and (MONSTRO_N < 63)):
MONSTRO_T = "Giant Lizard"
elif ((MONSTRO_N > 63) and (MONSTRO_N < 67)):
MONSTRO_T = "Giant Snapping Turtle"
elif ((MONSTRO_N > 67) and (MONSTRO_N < 71)):
MONSTRO_T = "LizardFolk"
elif ((MONSTRO_N > 71) and (MONSTRO_N < 74)):
MONSTRO_T = "Red Wizard"
elif ((MONSTRO_N > 74) and (MONSTRO_N < 84)):
MONSTRO_T = "Sea Hags"
elif ((MONSTRO_N > 84) and (MONSTRO_N < 87)):
MONSTRO_T = "Stirges"
elif ((MONSTRO_N > 87) and (MONSTRO_N < 89)):
MONSTRO_T = "Swarm of bats"
elif ((MONSTRO_N > 89) and (MONSTRO_N < 94)):
MONSTRO_T = "Tabaxy Hunter"
elif ((MONSTRO_N > 94) and (MONSTRO_N < 100)):
MONSTRO_T = "Tri-Flower Frond"

def noundead():
print("oioioi")

def Lundead():
print("oioioi")

def Gundead():
print("oioioi")

def mountains():
print("oioioi")

def rivers():
print("oioioi")

def ruins():
print("oioioi")

def swamp():
print("oioioi")

def wasteland():
print("oioioi")

def reset():
win.fill(white)
button("Facil",20,10,110,50,green,blue,black,white,ef)
button("Normal",150,10,110,50,green,blue,black,white,en)
button("Mortal",280,10,110,50,green,blue,black,white,em)
button("resete",410,10,110,50,green,blue,black,white,reset)
main()



def main():
while True:
for ev in pygame.event.get():
if ev.type == pygame.QUIT:
pygame.quit()
exit()
button("Facil",20,10,110,50,green,blue,black,white,ef)
button("Normal",150,10,110,50,green,blue,black,white,en)
button("Mortal",280,10,110,50,green,blue,black,white,em)
button("reset",410,10,110,50,green,blue,black,white,reset)

if encontro == 0:
button("Aguardando",930,10,300,50,green,blue,black,white)
elif encontro == 1:
button("Characters Level 1 to 4",930,10,300,50,green,blue,black,white)
elif encontro == 2:
button("Characters Level 4 to 8",930,10,300,50,green,blue,black,white)
elif encontro == 3:
button("Characters Level 8 or above",930,10,300,50,green,blue,black,white)

if encontro == 0:
button("Beach",20,100,110,50,green,blue,black,white,warning)
button("NoUndead",150,100,110,50,green,blue,black,white,warning)
button("- Undead",280,100,110,50,green,blue,black,white,warning)
button("+ undead",410,100,110,50,green,blue,black,white,warning)
button("Mountains",540,100,110,50,green,blue,black,white,warning)
button("Rivers",670,100,110,50,green,blue,black,white,warning)
button("Ruins",800,100,110,50,green,blue,black,white,warning)
button("Swamp",930,100,110,50,green,blue,black,white,warning)
button("Wasteland",1060,100,110,50,green,blue,black,white,warning)
button("Sair",1060,100,110,50,green,blue,black,white,quitgame)
elif encontro > 0:
win.fill(white)
if encontro == 1:
button("Characters Level 1 to 4",930,10,300,50,green,blue,black,white)
elif encontro == 2:
button("Characters Level 4 to 8",930,10,300,50,green,blue,black,white)
elif encontro == 3:
button("Characters Level 8 or above",930,10,300,50,green,blue,black,white)
button("Facil",20,10,110,50,green,blue,black,white,ef)
button("Normal",150,10,110,50,green,blue,black,white,en)
button("Mortal",280,10,110,50,green,blue,black,white,em)

button("Beach",20,100,110,50,green,blue,black,white,beach)
button("NoUndead",150,100,110,50,green,blue,black,white,noundead)
button("- Undead",280,100,110,50,green,blue,black,white,Lundead)
button("+ undead",410,100,110,50,green,blue,black,white,Gundead)
button("Mountains",540,100,110,50,green,blue,black,white,mountains)
button("Rivers",670,100,110,50,green,blue,black,white,rivers)
button("Ruins",800,100,110,50,green,blue,black,white,ruins)
button("Swamp",930,100,110,50,green,blue,black,white,swamp)
button("Wasteland",1060,100,110,50,green,blue,black,white,wasteland)
button("Sair",1060,100,110,50,green,blue,black,white,quitgame)


pygame.display.update()

main()

但是当我使用 reset() 函数时,一个循环使应用程序崩溃。我的功能有什么问题?我尝试使用很多东西,但我认为我的逻辑是错误的。我如何创建一个 reset() 函数来清除应用程序并重绘所有内容?或者,如何重新从头开始运行?

最佳答案

一般来说,一个好的 Stack Overflow 问题应该包含以下所有内容:

  • 有足够的问题代码来重现问题。 你给了我们!
  • 关于您希望代码如何运行的清晰描述。您已经解释了一点您希望“重置”按钮清除和重绘,这对今天来说可能已经足够清楚了。
  • 对代码实际 行为方式的清晰描述。在这种情况下,这意味着确切的错误消息。
  • 讨论您已尝试解决问题的方法。

在这种情况下,我想我已经能够重现您的问题。我添加了几个打印语句来帮助我查看流程,并运行了您的代码。在打印了无数次“reset”之后,我收到了这条错误信息:

Traceback (most recent call last):
File "SO_63564495.py", line 382, in <module>
main()
File "SO_63564495.py", line 334, in main
button("reset",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
File "SO_63564495.py", line 319, in reset
button("resete",410,10,110,50,green,blue,black,white,reset)
File "SO_63564495.py", line 42, in button
action()
[ELIDED because it is too damn long!]
File "/usr/lib/python3.8/posixpath.py", line 153, in dirname
sep = _get_sep(p)
File "/usr/lib/python3.8/posixpath.py", line 42, in _get_sep
if isinstance(path, bytes):
RecursionError: maximum recursion depth exceeded while calling a Python object

这就告诉我们问题所在:reset()是调用button(),后者又调用了reset(),没有限制直到程序崩溃。可能需要在 reset 内部发生一些事情,这样 pygame.mouse.get_pressed()[0] 将不再是 1 >按钮;我不确定。

也就是说,看起来您有点不知所措。如果您重新开始使用一个或另一个编程抽象来构建您的工作,那么您的代码中有很多可以改进的地方(变得更短、更容易阅读、更容易推理并说服我们自己相信其正确性) . Object Oriented Programming是一个很好的起点。

你承担了一个大项目;不要失去希望!

关于python - 如何正确实现复位功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63564495/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com