Skip to main content
 首页 » 编程设计

python之不知道如何摆脱列表中的这些 {} (python2.7)

2025年05月04日23sxdcgaq8080

我试过将列表转换成字符串,但我似乎无法摆脱括号:

import Tkinter 
import random 
window = Tkinter.Tk() 
window.geometry("250x150") 
window.title("Backstory_Generator") 
window.config(bg="black") 
 
Race=Tkinter.Entry(window, bd=10)#gui stuff 
Racee=Tkinter.Label(window,text="Race") 
Racee.config(bg="Black", fg="White") 
Race.config(bg="Grey") 
 
 
Class=Tkinter.Label(window,text="Class")#gui stuff 
Clas=Tkinter.Entry(window,bd=10) 
Class.config(bg="Black", fg="White") 
Clas.config(bg="Grey") 
 
def Select(): 
    text1 = random.randint(0,len(pb1)-1) 
    text2=random.randint(0,len(pb2)-1)#picks random number for word 
    text3=random.randint(0,len(pb3)-1) 
    text4 = random.randint(0,len(pb4)-1) 
    RaceChosen = Race.get()#retreus what entered 
    ClassChosen = Clas.get() 
    Result = Tkinter.Tk()#new window 
    Result.title("Result") 
    Result.config(bg="Black") 
    lol = "You are a",RaceChosen,"who has chosen to path of the",ClassChosen,"\n","you are " + pb1[text1] + " and craving for " + pb2[text2] + " ,You also are extremely " + pb3[text3] + " around others","\n","due to your " + pb4[text4] + " tendancies" 
    Line1 = Tkinter.Label(Result, text=lol)#outputs random thing 
    Line1.config(font=("Courier",15, "bold")) 
    Line1.config(bg="Black", fg="White", height = 10) 
    Line1.pack() 
    Result.geometry=("1000x250") 
    Result.mainloop() 
 
Generate = Tkinter.Button(window, text="Generate", command=Select) 
 
Racee.pack() 
Race.pack() 
Class.pack() 
Clas.pack() 
Generate.pack() 
 
 
window.mainloop() 

如您所见,括号看起来很奇怪,我似乎无法摆脱。我知道这个问题已被多次询问,但将列表转换为字符串并使用 .join(map) 对我不起作用。 有什么建议么?我遗漏了列表,因为它们包含一些明确的 Material ,所以是的:P

The output

请您参考如下方法:

看这一行:

lol = "You are a",RaceChosen,"who has chosen to path of the",ClassChosen,"\n","you are " + pb1[text1] + " and craving for " + pb2[text2] + " ,You also are extremely " + pb3[text3] + " around others","\n","due to your " + pb4[text4] + " tendancies" 

您创建的是元组而不是字符串。