我尝试将列表转换为字符串,但我似乎无法摆脱括号:
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)对我来说并不起作用。 有什么建议?我把列表排除了,因为它们包含一些明确的材料,所以是的:P
答案 0 :(得分:5)
看看这一行:
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"
你正在创建一个元组而不是一个字符串。