【问题标题】:Python tkinter message boxPython tkinter 消息框
【发布时间】:2018-12-26 05:15:31
【问题描述】:

我正在尝试找出与函数输出与整数比较有关的错误:

这是代码:

def qExit():
    tkinter.messagebox.askyesno('Quit system', 'Do you want to quit?')

    if qExit>0:
        root.destroy()
        return

这是我在消息框中按下“是”按钮时遇到的错误:

    if qExit>0:
TypeError: '>' not supported between instances of 'function' and 'int'

感谢您的帮助!

RB

【问题讨论】:

  • 你打算用qExit>0做什么?

标签: python tkinter


【解决方案1】:

是的,因为您收到的回复将采用string 格式,而您并未处理该回复。

在您的代码中,您没有将响应分配给任何变量,而是直接在条件验证中使用函数名称。您实际上是在进行“函数”和“int”比较。

【讨论】:

    【解决方案2】:

    请看下面的答案:

    def qExit():
        MsgBox = tkinter.messagebox.askyesno('Quit system', 'Do you want to quit?')
    
        if MsgBox > 0:
            root.destroy()
        else:
            tkinter.messagebox.showinfo('Return', 'You will now return to the application screen')
    

    【讨论】:

      猜你喜欢
      • 2021-08-04
      • 2020-10-07
      • 2012-08-14
      • 1970-01-01
      • 1970-01-01
      • 2013-06-22
      • 1970-01-01
      • 2013-07-28
      相关资源
      最近更新 更多