我试图制作一个程序,生成一个随机的字符设计,让我用python来绘制,但我试图让它每两分钟给我一个设计片段。当我使用时间。睡眠(120),它冻结并等待所有答案生成后再将它们放入列表框。有什么我可以改变的吗?你知道吗
def GenerateCharTimed():
import time
listbox.delete(0, END)
listbox.delete(1, END)
listbox.delete(2, END)
listbox.delete(3, END)
listbox.delete(4, END)
listbox.delete(5, END)
characterDrawn = random.choice(beings)
haircolor = random.choice(colors)
charhairstyle = random.choice(hairstyle)
features = random.choice(faceFeatures)
notperson = True
while notperson == True:
characterDrawn = random.choice(beings)
if characterDrawn == "man" or characterDrawn == "boy" or characterDrawn == "girl" or characterDrawn == "woman" or characterDrawn == "ghost" or characterDrawn == "vampire" or characterDrawn == "gnome" or characterDrawn == "skeleton" or characterDrawn == "gnome" or characterDrawn == "zombie" or characterDrawn == "plant monster" or characterDrawn == "humanoid" or characterDrawn == "monster":
notperson = False
if charhairstyle == "no hair":
character = "Your character is a " + characterDrawn + " with a " + features + " face, and with" + " " + charhairstyle + "."
character = str(character)
listbox.insert(END, character)
else:
character = "Your character is a " + characterDrawn + " with a " + features + " face, and with a " + haircolor + " " + charhairstyle
character = str(character)
listbox.insert(END, character)
time.sleep(120)
character = "Your character is wearing " + random.choice(clothing) + "."
character = str(character)
listbox.insert(END, character)
time.sleep(120)
adjLook1 = random.choice(adjectiveLook)
adjLook2 = random.choice(adjectiveLook)
adjLook3 = random.choice(adjectiveLook)
limb1 = random.choice(limbs)
limb2 = random.choice(limbs)
adjLookSimilar = False
if adjLook1 == adjLook2 or adjLook2 == adjLook3 or adjLook3 == adjLook1 or limb1 == limb2:
adjLookSimilar = True
while adjLookSimilar == True:
adjLook1 = random.choice(adjectiveLook)
adjLook2 = random.choice(adjectiveLook)
adjLook3 = random.choice(adjectiveLook)
limb1 = random.choice(limbs)
limb2 = random.choice(limbs)
if adjLook1 != adjLook2 and adjLook2 != adjLook3 and adjLook3 != adjLook1:
adjLookSimilar = False
character = "Your character has " + adjLook1 + " " + limb1 + "."
character = str(character)
listbox.insert(END, character)
time.sleep(120)
character = "Your character has " + adjLook2 + " " + limb2 + "."
character = str(character)
listbox.insert(END, character)
这可能不完全是您想要完成的,但请尝试以下操作以避免阻塞事件循环:
相关问题 更多 >
编程相关推荐