open uses passed-in encodingif anyor else prompts for an encoding name first save reuses known encoding if it has oneand otherwise prompts for new file saves save as always prompts for an encoding name first for the new file grep allows an encoding to be input in its dialog to apply to the full tree searched on the other handbecause the platform default will probably work silently without extra gui complexity for the vast majority of users anyhowthe textconfig setting can prevent the pop ups altogether and fall back on an explicit encoding or platform default ultimatelystructuring encoding selection well requires the sort of broad user experience and feedback which is outside this book' scopenot the guesses of single developer as alwaysfeel free to tailor as you like see the test subdirectory in the examples for few unicode text files to experiment with opening and savingin conjunction with textconfig changes as suggested when we saw figures - and - this directory contains files that use international character setssaved in different encodings for instancefile email-part--koi - there is formatted per the russian encoding koi -rand email-part--koi - --utf is the same file saved in utf- encoding formatthe latter works well in notepad on windowsbut the former will only display properly when giving an explicit encoding name to pyedit better yetmake few unicode files yourselfby changing textconfig to hardcode encodings or always ask for encodings--thanks largely to python ' unicode supportpyedit allows you to save and load in whatever encoding you wish more on quit checksthe event revisited before we get to the codeone of version ' changes merits few additional wordsbecause it illustrates the fundamentals of tkinter window closure in realistic context we learned in that tkinter also has event for the bind method which is run when windows and widgets are destroyed although we could bind this event on pyedit windows or their text widgets to catch destroys on program exitthis won' quite help with the use case here scripts cannot generally do anything guirelated in this event' callbackbecause the gui is being torn down in particularboth testing text widget for modifications and fetching its content in handler can fail with an exception popping up save verification dialog at this point may act oddlytooit only shows up after some of the window' widgets may have already been erased (including the text widget whose contents the user may wish to inspect and save!)and it might sometimes refuse to go away altogether as also mentioned in running quit method call does not trigger any eventsbut does trigger fatal python error message on exit to use destroy events at allpyedit would have to be redesigned to close windows on quit requests with the destroy method onlyand rely on the tk root window destruction protocol for exitsimmediate shutdowns would be unsupportedor require tools such as complete gui programs