如何确定客户端是否在tkinter消息框中选择了“确定”?

时间:2019-04-30 12:36:08

标签: python python-3.x tkinter tkmessagebox

对于我要创建的用于编辑MIDI文件的程序,我导入了tkinter.messagebox模块。我正在使用的消息框功能是askokcancel。我希望在选择 ok 后关闭所有父窗口和子窗口。我该怎么做?

我已经尝试在其他站点上查看操作方法,但没有找到任何答案。

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)

这只是我共享的代码示例。如果其他代码可能存在错误,我将与您分享。

1 个答案:

答案 0 :(得分:1)

public void intArray()
  {
    //create an int array called num that will store 4 elements
    int[] num = {32,26,19,40};
    //assign 32 to index 0  
    //assign 26 to index 1 
    //assign 19 to index 2  
    //assign 40 to index 3 
    //change index 3 to 57
    num[3] = 57;
  }
  //write a line of code to print length of array:  Length of array of :  
  public static void main(String[]args)
  {
    System.out.println("The length of the array is " + num.length);
    //write a line of code to print index 3:  Index 3 is :    
    System.out.println("Index three is " + num[3]);
    //create a for loop to loop through and print all elements in the array
    for(int element: num)
    {
      System.out.println(element);
    }
  }

enter image description here

或:

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

enter image description here