0

The documentation I have seen on tkMessageBox seems to indicate a boolean return for a user choice on an askyesnocancel dialog. There are 3 options, so how can a boolean properly capture the user choice?

I've tried the approach shown below where a "yes" returns "True", "no" returns "False" and "cancel" returns "cancel", but that doesn't seem to work. A "no" or "cancel" selection both seem to be returned as "False". Anybody have any ideas on this?

if tkMessageBox.askyesnocancel("Error", "Choose yes, no or cancel", default='yes')
    ...
    ...
    ...

elif "cancel":
    return
else:
    pass
4

1 回答 1

4

实际上,点击Cancel返回None。只需使用此行进行测试:

repr(tkMessageBox.askyesnocancel("wa", "wa"))

总之,“是”收益率True、“否”收益率False和“取消”收益率None

您遇到的问题是 的布尔值None也是False。您必须明确检查None

 if result is None:
     ...
于 2015-02-28T14:52:37.317 回答