簡體   English   中英

Python tkinter 消息框

[英]Python tkinter message box

我試圖找出與函數輸出與整數的比較有關的錯誤:

這是代碼:

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

是的,因為您收到的響應將采用string格式,並且您沒有處理該響應。

在您的代碼中,您沒有將響應分配給任何變量,也沒有在條件驗證中直接使用函數名稱。 您實際上是在進行“函數”和“整數”比較。

請參閱下面的答案:

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