Changing the editor's font
As we saw from our blackjack game, fonts in Tkinter are usually handled by a font
argument against a widget. The Text
widget is no exception, this takes the same argument in the same format—a tuple of (family, size, styles).
To change the font in our text editor, we could decide ourselves what font the editor should be in and hard-code that into the declaration of our TextArea
instance. However, we cannot guarantee that the user has that font installed, nor can we assume that they like writing in that font! We also cannot assume what font size the user can read best. The only solution is to allow the user to choose their own font settings and find a way of saving their chosen configuration for the next time they open our application.
Since .yaml
files are working out so well, we shall just use these for persistent storage.
Note
Other options for persistent storage include plain text files, pickle, shelve or SQLite (which will be covered in a later chapter of this book...