Issue #11896: Save on Close failed despite selecting "Yes" in dialog.

Backport 70055:35ed0efd7dd3
diff --git a/Lib/idlelib/IOBinding.py b/Lib/idlelib/IOBinding.py
index a5b610e..a8c351f 100644
--- a/Lib/idlelib/IOBinding.py
+++ b/Lib/idlelib/IOBinding.py
@@ -320,17 +320,20 @@
             return "yes"
         message = "Do you want to save %s before closing?" % (
             self.filename or "this untitled document")
-        m = tkMessageBox.Message(
-            title="Save On Close",
-            message=message,
-            icon=tkMessageBox.QUESTION,
-            type=tkMessageBox.YESNOCANCEL,
-            master=self.text)
-        reply = m.show()
-        if reply == "yes":
+        confirm = tkMessageBox.askyesnocancel(
+                  title="Save On Close",
+                  message=message,
+                  default=tkMessageBox.YES,
+                  master=self.text)
+        if confirm:
+            reply = "yes"
             self.save(None)
             if not self.get_saved():
                 reply = "cancel"
+        elif confirm is None:
+            reply = "cancel"
+        else:
+            reply = "no"
         self.text.focus_set()
         return reply
 
@@ -339,7 +342,7 @@
             self.save_as(event)
         else:
             if self.writefile(self.filename):
-                self.set_saved(1)
+                self.set_saved(True)
                 try:
                     self.editwin.store_file_breaks()
                 except AttributeError:  # may be a PyShell
@@ -465,15 +468,12 @@
             self.text.insert("end-1c", "\n")
 
     def print_window(self, event):
-        m = tkMessageBox.Message(
-            title="Print",
-            message="Print to Default Printer",
-            icon=tkMessageBox.QUESTION,
-            type=tkMessageBox.OKCANCEL,
-            default=tkMessageBox.OK,
-            master=self.text)
-        reply = m.show()
-        if reply != tkMessageBox.OK:
+        confirm = tkMessageBox.askokcancel(
+                  title="Print",
+                  message="Print to Default Printer",
+                  default=tkMessageBox.OK,
+                  master=self.text)
+        if not confirm:
             self.text.focus_set()
             return "break"
         tempfilename = None
@@ -488,8 +488,8 @@
             if not self.writefile(tempfilename):
                 os.unlink(tempfilename)
                 return "break"
-        platform=os.name
-        printPlatform=1
+        platform = os.name
+        printPlatform = True
         if platform == 'posix': #posix platform
             command = idleConf.GetOption('main','General',
                                          'print-command-posix')
@@ -497,7 +497,7 @@
         elif platform == 'nt': #win32 platform
             command = idleConf.GetOption('main','General','print-command-win')
         else: #no printing for this platform
-            printPlatform=0
+            printPlatform = False
         if printPlatform:  #we can try to print for this platform
             command = command % filename
             pipe = os.popen(command, "r")
@@ -511,7 +511,7 @@
                 output = "Printing command: %s\n" % repr(command) + output
                 tkMessageBox.showerror("Print status", output, master=self.text)
         else:  #no printing for this platform
-            message="Printing is not enabled for this platform: %s" % platform
+            message = "Printing is not enabled for this platform: %s" % platform
             tkMessageBox.showinfo("Print status", message, master=self.text)
         if tempfilename:
             os.unlink(tempfilename)