官术网_书友最值得收藏!

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()
主站蜘蛛池模板: 普洱| 中阳县| 高尔夫| 青冈县| 汝南县| 宽城| 怀远县| 济源市| 武功县| 灵台县| 徐汇区| 类乌齐县| 吉首市| 临沭县| 永昌县| 农安县| 永修县| 孝义市| 彰化县| 铜川市| 天柱县| 青州市| 桃源县| 常宁市| 玉田县| 左贡县| 河南省| 邳州市| 盈江县| 澄城县| 忻城县| 博湖县| 西乌| 工布江达县| 家居| 武汉市| 巴里| 威海市| 福鼎市| 游戏| 乳山市|