-2

我写了以下代码

    closeButton = Button(self, text="Close",command=self.askyesno)
    closeButton.pack(side=RIGHT, padx=5, pady=5)
    okButton = Button(self, text="OK")
    okButton.pack(side=RIGHT)

def askyesno():
    res = tkMessageBox.askokcancel(title="Quit", message="Do you want to quit?")
    if res == "yes":
    self.quit()

每当我按下关闭按钮时,python 都会崩溃并显示消息类型错误:askyesno() 不接受任何参数,给定 1。网上有很多像我这样的例子。我确信他们工作。我究竟做错了什么。我发现的所有示例都有这个问题,并且 tkMessageBox 的文档没有提供任何示例。

4

1 回答 1

1

这不是 tkMessageBox,而是您的功能。你应该这样定义它:

#def askyesno():    # Not like this
def askyesno(self):

假设它是一个类的成员。

于 2016-06-07T16:58:52.203 回答