当我打开一个tkinter窗口供用户输入玩家名称时,玩家名称将成为包含玩家在游戏中得分的保存文件名,tkinter窗口会打开,只要点击提交按钮,游戏本质上是冻结的,我必须关闭游戏。我怎么阻止它冻结?这是代码:
print(str(redpoints))
print(str(yellowpoints))
master = Tk()
master.title('Save File Name')
v = StringVar()
# Variable to hold the input
inp = None
L1 = Label(master, text = 'Enter Player Names:')
L1.pack(side = LEFT)
E1 = Entry(master, textvariable = v, bd = 5)
E1.pack(side = RIGHT)
def userinput():
# Declare 'inp' to be global
global inp
savename = input(v.get())
print (savename)
# Update the variable
inp = savename
Submit = Button(master, text = 'Submit', command = userinput)
Submit.pack(side = BOTTOM)
print(inp)
master.mainloop()
answer = (str(redpoints), " ", str(yellowpoints))
example = open(inp + '.txt', 'w') #opening the file, 'w' allows to write in it.
example.write(answer)
example.close()
pygame.quit()
quit()
在用户输入= savename
之前崩溃