For a program I'm creating which edits MIDI files, I imported the tkinter.messagebox
module. The messagebox function I'm using is 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.