簡體   English   中英

如何確定客戶端是否在tkinter消息框中選擇了“確定”?

[英]How to determine if a client selected “ok” in a tkinter messagebox?

對於要創建的用於編輯MIDI文件的程序,我導入了tkinter.messagebox模塊。 我正在使用的消息框功能是askokcancel 我希望在選擇“ 確定”后關閉所有父窗口和子窗口。 我該如何完成?

我已經嘗試過在其他站點上查看操作方法,但是沒有找到任何答案。

from tkinter import *
import tkinter.messagebox

class Window(Frame):

        def init_window(self):

        menu = Menu(self.master)

        self.master.config(menu=menu)

        file = Menu(menu)

        file.add_command(label="Exit", command=self.client_exit)

        menu.add_cascade(label="File", menu=file)

    def exit(self):

        exit()

    def client_exit(self):

        messagebox.askokcancel('Exit?', 'Are you sure you want to exit?', default='ok') 

#Here, I want the "exit" function to be the function.

        if self.reading:

            self.top.quit()

app = Window(tk)

這只是我共享的代碼的一個示例。 如果其他代碼可能存在錯誤,我將與您分享。

def client_exit(self):
    MsgBox = messagebox.showinfo('Exit?', 'Are you sure you want to exit?',icon = 'warning')
    if MsgBox == 'ok':
        #Some code

在此處輸入圖片說明

要么:

def client_exit(self):
    MsgBox = messagebox.askquestion ('Exit?', 'Are you sure you want to exit?',icon = 'warning')
    if MsgBox == 'yes':
        # Your code
    else:
        # Your code

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM