Setting up the editor skeleton

Our first goal is to implement the broad visual elements of the text editor. As programmers, we have all used text editors to edit code. We are mostly aware of the common GUI elements of a text editor. So, without much of an introduction, let's get started.

The first phase implements the Menu, Menubutton, Label, Button, Text and Scrollbar widgets. Although we'll cover all of these in detail, you might find it helpful to look at the widget-specific options in the documentation of Tkinter maintained by its author Frederick Lundh at http://effbot.org/tkinterbook/. You can also use the interactive shell, as discussed in Chapter 1, Meet Tkinter.

You might also want to bookmark the official documentation page of Tcl/Tk at http://www.tcl.tk/man/tcl8.6/TkCmd/contents.htm. This site includes the original Tcl/Tk reference. While it does not relate to Python, it provides a detailed overview of each widget and is a useful reference. Remember that Tkinter is just a wrapper around Tk.

In this iteration, we will complete the implementation of broader visual elements of the editor.

We will use the pack() geometry manager to place all the widgets. We have chosen the pack manager because it is ideally suited for the placing of widgets side by side or in a top-down position. Fortunately, in a text editor, we have all the widgets placed either side-by-side or in top-down locations. Thus, it is beneficial to use the pack manager. We can do the same thing with the grid manager as well.

Note

A note on code styling

One of the key insights of the Python community is that code is read much more often than it is written. Following good naming conventions and consistency in code styling are keys to maintaining readable and scalable programs.

We will try to stick to the official Python styling guide, which is specified in the PEP8 documentation at https://www.python.org/dev/peps/pep-0008.

Some important styling conventions that we will stick to include the following:

  • Use 4 spaces per indentation level
  • The variable and function names will be lowercase, with words separated by underscores
  • The class names will use the CapWords convention

Lets start by adding the Toplevel window by using the following code:

from tkinter import *
root = Tk()
# all our code goes here
root.mainloop()