tkinter销毁不起作用

时间:2017-01-05 18:26:03

标签: python python-3.x tkinter

所以我用python和tkinter编写游戏,我需要一个弹出窗口,当游戏结束时,但是当我点击“再次播放”按钮时,它不会破坏弹出窗口。此外,弹出窗口上的消息显示为大括号,即“{Game over,player} red wins!

这是弹出窗口代码:

def gameOverPopup(winOrTie):
    if winOrTie==True:
    lText=("Game over, player",player,"wins!")
else:
    lText=("Game over, board full!")
popup=tk.Toplevel()
winLabel=tk.Label(popup,text=lText)
winLabel.grid(column=1,row=1,padx=50,pady=25)
againButton=tk.Button(popup,text="Play again",command=resetGame(popup))
againButton.grid(column=1,row=2,padx=50,pady=25)
endButton=tk.Button(popup,text="Quit",command=window.destroy)
endButton.grid(column=1,row=3,padx=50,pady=25)

def resetGame(popup):
    popup.destroy

1 个答案:

答案 0 :(得分:1)

您需要使用括号来调用destroy

popup.destroy()

要正确显示消息,它必须是字符串而不是元组:

lText="Game over, player %s wins!" %player