“按钮”对象在第二次使用时不可调用

时间:2018-07-17 19:14:33

标签: python button tkinter

因此,此脚本是一款文本游戏,可从玩家处获取输入并输出故事。我一直在为此做一个基本的GUI。要求之一是保存并重播选项。我已经运行了脚本,并且运行得很好……一次。按下重播按钮后,它将再次启动游戏功能并一直运行到出现此错误的结尾:

第99行,在text_output中     self.replay_button()

TypeError:“按钮”对象不可调用

我感到很困惑的是,脚本已经在这一行代码上运行了一次,没有任何错误。我尝试使用grid.forget而不是销毁按钮,但是收到了相同的错误。

#some code that runs the gameplay
def text_output(self):
    self.T = Text(root, height=7, width=100)
    self.T.grid(column=1, row=5, pady=20)
    self.T.insert(END, contentSplit)
    self.entry.destroy()
    self.pull = ("Here's your story!")
    self.phrase_text.set(self.pull)
    self.replay_button()
    self.save_button()


def replay_button(self):
    self.replay_button = Button(root, text="Play Again", command=self.replay_game)
    self.replay_button.grid(column=0, row=6, sticky=W)


def save_button(self):
    self.save_button = Button(root, text="Save", command=self.save_story)
    self.save_button.grid(column=2, row=6, sticky=E)

def replay_game(self):
    self.save_button.destroy()
    self.replay_button.destroy()
    self.T.destroy()
    self.entry_box()
    self.entry.focus()
    self.game_play()

0 个答案:

没有答案