def writefile(self, filename): self.fixlastline() chars = self.encode(self.text.get("1.0", "end-1c")) if self.eol_convention != "\n": chars = chars.replace("\n", self.eol_convention) try: f = open(filename, "wb") f.write(chars) f.flush() f.close() return True except IOError as msg: tkMessageBox.showerror("I/O Error", str(msg), master=self.text) return False