[英]How to determine if a client selected “ok” in a tkinter messagebox?
For a program I'm creating which edits MIDI files, I imported the tkinter.messagebox
module. 对于要创建的用于编辑MIDI文件的程序,我导入了tkinter.messagebox
模块。 The messagebox function I'm using is askokcancel
. 我正在使用的消息框功能是askokcancel
。 I want all the parent and child windows to close when ok is selected. 我希望在选择“ 确定”后关闭所有父窗口和子窗口。 How do I accomplish this? 我该如何完成?
I've already tried going on other sites to see how, but I didn't find any answers. 我已经尝试过在其他站点上查看操作方法,但是没有找到任何答案。
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)
This is just a sample of my code I shared. 这只是我共享的代码的一个示例。 If there is a possible error with the other code, I'll share it. 如果其他代码可能存在错误,我将与您分享。
def client_exit(self):
MsgBox = messagebox.showinfo('Exit?', 'Are you sure you want to exit?',icon = 'warning')
if MsgBox == 'ok':
#Some code
or: 要么:
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.