I am trying to write data to a file in a non-roman script using python tkinter. I want to write data to a file in Hindi language which follows the Devanagari Script. While, it is working perfectly alright when I write some data in English, while writing to the file in Hindi language is throwing some errors. How do I resolve this issue?
I tried adding (encoding='utf-8') in filedialog command. Doing this, it gives the following error:
_tkinter.TclError: bad option "-encoding": must be -confirmoverwrite, -defaultextension, -filetypes, -initialdir, -initialfile, -parent, -title, or -typevariable
This error shows up the moment I click the button.Maybe (encoding='utf-8') is not an attribute of filedialog. Following is the relevant part of the code:
def save_file_hindi(event=""):
data = filedialog.asksaveasfile(mode="w", defaultextension=".html")
if data is None:
return
data.write("एक" + "<br>\n"+ "दो" + "<br>\n")
data.close()
Expected Result: In the saved HTML file, it should display:
एक
दो
Actual Result: UnicodeEncodeError: 'charmap' codec can't encode characters in position 19-26: character maps to undefined