to span multiple rows or columns, so you have some flexibility in how the widgets appear.
The grid() method defines three parameters for placing the widget in the window:
Click here to view code image
object.grid(row = x, column = y, sticky = n)
The row and column values refer to the cell location in the layout, starting with row 0 and column 0
as the top-left cell in the window. The sticky parameter tells Python how to align the widget inside
the cell. There are nine possible sticky values:
N—Places the widget at the top of the cell.
S—Places the widget at the bottom of the cell.
E—Right-aligns the widget in the cell.
W—Left-aligns the widget in the cell.
NE—Places the widget at the top-right corner of the cell.
NW—Places the widget at the top-left corner of the cell.
SE—Places the widget at the bottom-right corner of the cell.
SW—Places the widget at the bottom-left corner of the cell.
CENTER—Centers the widget in the cell.
In this hour, you’ll use the grid method of positioning the widgets.
Defining Widgets
Now that you have a Frame object and a positioning method, you’re ready to start placing some
widgets inside your window. You can define widgets directly in the class constructor for the
Application class, but it’s become somewhat standard in Python circles to create a special
method called create_widgets() and then place the statements to create the widgets inside that
method. You can just call the create_widgets() method from inside the class constructor.
When you add the create_widgets() method to the Application class, the constructor looks
like this:
Click here to view code image
def __init__(self, master):
super(Application, self).__init__(master)
self.grid()
self.create_widgets()
The create_widgets() method contains all the statements to build the widget objects that you
want to appear in your window. Listing 18.3 shows the script1803.py program, which
demonstrates a simple example of this.
LISTING 18.3 The script1803.py File
Click here to view code image
1: #!/usr/bin/python3
2: from tkinter import *
3: