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

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()
主站蜘蛛池模板: 黄平县| 濮阳县| 扶绥县| 驻马店市| 岑溪市| 米林县| 永仁县| 阜阳市| 疏勒县| 三穗县| 阳谷县| 泰来县| 长阳| 禄丰县| 静宁县| 桂平市| 灵寿县| 冷水江市| 宜川县| 定远县| 潮安县| 辽中县| 镇雄县| 娱乐| 五莲县| 白银市| 高淳县| 金华市| 应城市| 麦盖提县| 七台河市| 义乌市| 梓潼县| 新巴尔虎左旗| 大竹县| 郴州市| 白山市| 云和县| 合肥市| 临湘市| 山东省|