简体   繁体   English

Python tkinter 消息框

[英]Python tkinter message box

I'm trying to figure out an error I get that is related to comparison of function output with an integer:我试图找出与函数输出与整数的比较有关的错误:

This is the code:这是代码:

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

    if qExit>0:
        root.destroy()
        return

This is the error I get whenever I press press the yes button in the message box:这是每当我按下消息框中的“是”按钮时出现的错误:

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

Thanks for the help!谢谢您的帮助!

RB RB

Yes, because the response you are receiving will be in string format and you are not handling that response.是的,因为您收到的响应将采用string格式,并且您没有处理该响应。

Here in your code, you are not assigning the response to any variable and using function name directly in condition validation.在您的代码中,您没有将响应分配给任何变量,也没有在条件验证中直接使用函数名称。 You are literally doing "function" and "int" comparison.您实际上是在进行“函数”和“整数”比较。

See answer below:请参阅下面的答案:

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')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM