272 Chapter 9 GUI Programming Using Tkinter
9.1 Introduction
Key
Tkinter enables you to develop GUI programs and is an excellent pedagogical tool for
Point learning object-oriented programming.
There are many GUI modules available for developing GUI programs in Python. You have
used the turtle module for drawing geometric shapes. Turtle is easy to use and is an
effective pedagogical tool for introducing the fundamentals of programming to beginners.
However, you cannot use turtle to create graphical user interfaces. This chapter introduces
what is Tkinter? Tkinter, which will enable you to develop GUI projects. Tkinter is not only a useful tool for
developing GUI projects, but it is also a valuable pedagogical tool for learning object-
oriented programming.
Note
Tkinter (pronounced T-K-Inter) is short for “Tk interface.” Tk is a GUI library used by
many programming languages for developing GUI programs on Windows, Mac, and
UNIX. Tkinter provides an interface for Python programmers to use the Tk GUI library,
and it is the de-facto standard for developing GUI programs in Python.
9.2 Getting Started with Tkinter
The tkinter module contains the classes for creating GUIs. The Tk class creates a
Key
Point window for holding GUI widgets (i.e., visual components).
Listing 9.1 introduces Tkinter with a simple example.
LISTING 9.1 [Link]
1 from tkinter import * # Import all definitions from tkinter
2
create a window 3 window = Tk() # Create a window
create a label 4 label = Label(window, text = "Welcome to Python") # Create a label
create a button 5 button = Button(window, text = "Click Me") # Create a button
place label 6 [Link]() # Place the label in the window
place button 7 [Link]() # Place the button in the window
8
event loop 9 [Link]() # Create an event loop
When you run the program, a label and a button appear in the Tkinter window, as shown in
Figure 9.1.
FIGURE 9.1 The label and button are created in Listing 9.1.
Whenever you create a GUI-based program in Tkinter, you need to import the tkinter
module (line 1) and create a window by using the Tk class (line 3). Recall that the asterisk (*) in
line 1 imports all definitions for classes, functions, and constants from the tkinter module to
the [Link]() creates an instance of a window. Label and Button are Python Tkinter
9.3 Processing Events 273
widget classes for creating labels and buttons. The first argument of a widget class is always the widget class
parent container (i.e., the container in which the widget will be placed). The statement (line 4) parent container
label = Label(window, text = "Welcome to Python")
constructs a label with the text Welcome to Python that is contained in the window.
The statement (line 6)
[Link]()
places label in the container using a pack manager. In this example, the pack manager packs
the widget in the window row by row. More on the pack manager will be introduced in
Section 9.6.2. For now, you can use the pack manager without knowing its full details.
Tkinter GUI programming is event driven. After the user interface is displayed, the pro-
gram waits for user interactions such as mouse clicks and key presses. This is specified in the
following statement (line 9)
[Link]()
The statement creates an event loop. The event loop processes events continuously until
you close the main window, as shown in Figure 9.2.
Start event loop
Detect and
process events
Close the No
main window?
Yes
Terminate
FIGURE 9.2 A Tkinter GUI program listens and processes events in a continuous loop.
9.1 What are turtle and Tkinter suitable for?
9.2 How do you create a window? ✓ Check
Point
9.3 What is [Link]() for?
9.3 Processing Events
A Tkinter widget can be bound to a function, which is called when an event occurs.
Key
The Button widget is a good way to demonstrate the basics of event-driven programming, so Point
we’ll use it in the following example.
When the user clicks a button, your program should process this event. You enable this
action by defining a processing function and binding the function to the button, as shown in VideoNote
Listing 9.2. Simple GUI
274 Chapter 9 GUI Programming Using Tkinter
LISTING 9.2 [Link]
1 from tkinter import * # Import all definitions from tkinter
2
process OK 3 def processOK():
4 print("OK button is clicked")
5
process Cancel 6 def processCancel():
7 print("Cancel button is clicked")
8
create a window 9 window = Tk() # Create a window
create a button 10 btOK = Button(window, text = "OK", fg = "red", command = processOK)
create a button 11 btCancel = Button(window, text = "Cancel", bg = "yellow",
12 command = processCancel)
place button 13 [Link]() # Place the OK button in the window
place button 14 [Link]() # Place the Cancel button in the window
15
event loop 16 [Link]() # Create an event loop
When you run the program, two buttons appear, as shown in Figure 9.3a. You can watch
the events being processed and see their associated messages in the command window in
Figure 9.3b.
(a) (b)
FIGURE 9.3 (a) Listing 9.2 displays two buttons in a window. (b) Watching events being
processed in the command window.
The program defines the functions processOK and processCancel (lines 3–7). These
functions are bound to the buttons when the buttons are constructed. These functions are
callback functions known as callback functions, or handlers. The following statement (line 10)
handlers
btOK = Button(window, text = "OK", fg = "red", command = processOK)
binds the OK button to the processOK function, which will be called when the button is
clicked. The fg option specifies the button’s foreground color and the bg option specifies its
background color. By default, fg is black and bg is gray for all widgets.
You can also write this program by placing all the functions in one class, as shown in
Listing 9.3.
LISTING 9.3 [Link]
1 from tkinter import * # Import all definitions from tkinter
2
3 class ProcessButtonEvent:
initialize GUI 4 def _ _init_ _(self):
5 window = Tk() # Create a window
create a button 6 btOK = Button(window, text = "OK", fg = "red",
7 command = [Link] )
create a button 8 btCancel = Button(window, text = "Cancel", bg = "yellow",
9 command = [Link] )
9.4 The Widget Classes 275
10 [Link]() # Place the OK button in the window place button
11 [Link]() # Place the Cancel button in the window place button
12
13 [Link]() # Create an event loop event loop
14
15 def processOK(self): process OK
16 print("OK button is clicked")
17
18 def processCancel(self): process Cancel
19 print("Cancel button is clicked")
20
21 ProcessButtonEvent() # Create an object to invoke _ _init_ _ method
The program defines a class for creating the GUI in the _ _init_ _ method (line 4). The
functions processOK and processCancel are now instance methods in the class, so they
are called by [Link] (line 7) and [Link] (line 9).
There are two advantages of defining a class for creating a GUI and processing GUI
events. First, you can reuse the class in the future. Second, defining all the functions as meth-
ods enables them to access instance data fields in the class.
9.4 When you create a widget object from a widget class, what should be the first
argument?
9.5 What is a widget’s command option for?
✓ Check
Point
9.4 The Widget Classes
Tkinter’s GUI classes define common GUI widgets such as buttons, labels, radio
Key
buttons, check buttons, entries, canvases, and others. Point
Table 9.1 describes the core widget classes Tkinter provides.
TABLE 9.1 Tkinter Widget Classes
Widget Class Description
Button A simple button, used to execute a command.
Canvas Structured graphics, used to draw graphs and plots, create graphics editors, and implement custom widgets.
Checkbutton Clicking a check button toggles between the values.
Entry A text entry field, also called a text field or a text box.
Frame A container widget for containing other widgets.
Label Displays text or an image.
Menu A menu pane, used to implement pull-down and popup menus.
Menubutton A menu button, used to implement pull-down menus.
Message Displays a text. Similar to the label widget, but can automatically wrap text to a given width or aspect ratio.
Radiobutton Clicking a radio button sets the variable to that value, and clears all other radio buttons associated with the same
variable.
Text Formatted text display. Allows you to display and edit text with various styles and attributes. Also supports
embedded images and windows.
There are many options for creating widgets from these classes. The first argument is
always the parent container. You can specify a foreground color, background color, font, and
cursor style when constructing a widget.
276 Chapter 9 GUI Programming Using Tkinter
color To specify a color, use either a color name (such as red, yellow, green, blue, white, black,
purple) or explicitly specify the red, green, and blue (RGB) color components by using a
string #RRGGBB, where RR, GG, and BB are hexadecimal representations of the red, green, and
blue values, respectively.
font You can specify a font in a string that includes the font name, size, and style. Here are
some examples:
Times 10 bold
Helvetica 10 bold italic
CourierNew 20 bold italic
Courier 20 bold italic overstrike underline
text formatting By default, the text in a label or a button is centered. You can change its alignment by
using the justify option with the named constants LEFT, CENTER, or RIGHT. (Remember,
as discussed in Section 2.6, named constants are in all uppercase.) You can also display the
text in multiple lines by inserting the newline character \n to separate lines of text.
mouse cursor You can specify a particular style of mouse cursor by using the cursor option with string
values such as arrow (the default), circle, cross, plus, or some other shape.
When you construct a widget, you can specify its properties such as fg, bg, font,
change properties cursor, text, and command in the constructor. Later in the program, you can change the
widget’s properties by using the following syntax:
widgetName["propertyName"] = newPropertyValue
For example, the following code creates a button and its text property is changed to
Hide, bg property to red, and fg to #AB84F9. #AB84F9 is a color specified in the form of
RRGGBB.
btShowOrHide = Button(window, text = "Show", bg = "white")
btShowOrHide["text"] = "Hide"
btShowOrHide["bg"] = "red"
btShowOrHide["fg"] = "#AB84F9" # Change fg color to #AB84F9
btShowOrHide["cursor"] = "plus" # Change mouse cursor to plus
btShowOrHide["justify"] = LEFT # Set justify to LEFT
Each class comes with a substantial number of methods. The complete information about
these classes is beyond the scope of this book. A good reference resource for Tkinter can be
found at [Link]/library/tkinter. This chapter provides examples that show you
how to use these widgets.
Listing 9.4 is an example of a program that uses the widgets Frame, Button,
Checkbutton, Radiobutton, Label, Entry (also known as a text field), Message, and
Text (also known as a text area).
LISTING 9.4 [Link]
1 from tkinter import * # Import all definitions from tkinter
2
3 class WidgetsDemo:
4 def _ _init_ _(self):
create a window 5 window = Tk() # Create a window
window title 6 [Link]("Widgets Demo") # Set a title
7
8 # Add a check button, and a radio button to frame1
create frame 9 frame1 = Frame(window) # Create and add a frame to window
10 [Link]()
11 self.v1 = IntVar()
9.4 The Widget Classes 277
12 cbtBold = Checkbutton(frame1, text = "Bold", create check button
13 variable = self.v1 , command = [Link] )
14 self.v2 = IntVar()
15 rbRed = Radiobutton(frame1, text = "Red", bg = "red", create radio button
16 variable = self.v2 , value = 1,
17 command = [Link] )
18 rbYellow = Radiobutton(frame1, text = "Yellow",
19 bg = "yellow", variable = self.v2, value = 2,
20 command = [Link] )
21 [Link](row = 1, column = 1) grid manager
22 [Link](row = 1, column = 2)
23 [Link](row = 1, column = 3)
24
25 # Add a label, an entry, a button, and a message to frame1
26 frame2 = Frame(window) # Create and add a frame to window create frame
27 [Link]()
28 label = Label(frame2, text = "Enter your name: ")
29 [Link] = StringVar()
30 entryName = Entry(frame2, textvariable = [Link] ) create entry
31 btGetName = Button(frame2, text = "Get Name",
32 command = [Link])
33 message = Message(frame2, text = "It is a widgets demo") create message
34 [Link](row = 1, column = 1)
35 [Link](row = 1, column = 2)
36 [Link](row = 1, column = 3)
37 [Link](row = 1, column = 4)
38
39 # Add text
40 text = Text(window) # Create and add text to the window create text
41 [Link]()
42 [Link](END, insert text
43 "Tip\nThe best way to learn Tkinter is to read ")
44 [Link](END,
45 "these carefully designed examples and use them ")
46 [Link](END, "to create your applications.")
47
48 [Link]() # Create an event loop event loop
49
50 def processCheckbutton(self):
51 print("check button is "
52 + ("checked " if [Link]() == 1 else "unchecked")) check button status
53
54 def processRadiobutton(self):
55 print(("Red" if [Link]() == 1 else "Yellow") radio button status
56 + " is selected " )
57
58 def processButton(self):
59 print("Your name is " + [Link]()) entry name
60
61 WidgetsDemo() # Create GUI create GUI
When you run the program, the widgets are displayed as shown in Figure 9.4a. As you
click the Bold button, select the Yellow radio button, and type in “Johnson,” you can watch
the events being processed and see their associated messages in the command window in
Figure 9.4b.
The program creates the window (line 5) and invokes its title method to set a title (line
6). The Frame class is used to create a frame named frame1 and the parent container for the
frame is the window (line 9). This frame is used as the parent container for a check button and
two radio buttons, created in lines 12, 15, and 18.
278 Chapter 9 GUI Programming Using Tkinter
(a) (b)
FIGURE 9.4 (a) The widgets are displayed in the user interface. (b) Watching events being processed.
IntVar You use an entry (text field) for entering a value. The value must be an object of IntVar,
DoubleVar DoubleVar, or StringVar representing an integer, a float, or a string, respectively. IntVar,
StringVar DoubleVar, and StringVar are defined in the tkinter module.
The program creates a check button and associates it with the variable v1. v1 is an
instance of IntVar (line 11). v1 is set to 1 if the check button is checked, or 0 if it isn’t
checked. When the check button is clicked, Python invokes the processCheckbutton
method (line 13).
The program then creates a radio button and associates it with an IntVar variable, v2. v2
is set to 1 if the Red radio button is selected, or 2 if the Yellow radio button is checked. You
can define any integer or string values when constructing a radio button. When either of the
two buttons is clicked, the processRadiobutton method is invoked.
geometry manager The grid geometry manager is used to place the check button and radio buttons into
frame1. These three widgets are placed in the same row and in columns 1, 2, and 3, respec-
tively (lines 21–23).
The program creates another frame, frame2 (line 26), for holding a label, an entry, a button,
and a message widget. Like frame1, frame2 is placed inside the window.
An entry is created and associated with the variable name of the StringVar type for stor-
ing the value in the entry (line 29). When you click the Get Name button, the processButton
method displays the value in the entry (line 59). The Message widget is like a label except that
it automatically wraps the words and displays them in multiple lines.
The grid geometry manager is used to place the widget in frame2. These widgets are
placed in the same row and in columns 1, 2, 3, and 4, respectively (lines 34–37).
The program creates a Text widget (line 40) for displaying and editing text. It is placed
inside the window (line 41). You can use the insert method to insert text into this widget.
The END option specifies that the text is inserted into the end of the current content.
Listing 9.5 is a program that lets the user change the color, font, and text of a label, as
shown in Figure 9.5.
LISTING 9.5 [Link]
1 from tkinter import * # Import all definitions from tkinter
2
3 class ChangeLabelDemo:
4 def _ _init_ _(self):
5 window = Tk() # Create a window
window title 6 [Link]("Change Label Demo") # Set a title
7
8 # Add a label to frame1
create frame1 9 frame1 = Frame(window) # Create and add a frame to window
10 [Link]()
create label 11 [Link] = Label(frame1, text = "Programming is fun")
12 [Link]()
13
9.4 The Widget Classes 279
14 # Add a label, entry, button, two radio buttons to frame2
15 frame2 = Frame(window) # Create and add a frame to window create frame2
16 [Link]()
17 label = Label(frame2, text = "Enter text: ")
18 [Link] = StringVar()
19 entry = Entry(frame2, textvariable = [Link]) create entry
20 btChangeText = Button(frame2, text = "Change Text",
21 command = [Link]) button callback
22 self.v1 = StringVar()
23 rbRed = Radiobutton(frame2, text = "Red", bg = "red",
24 variable = self.v1, value = 'R',
25 command = [Link]) radio button callback
26 rbYellow = Radiobutton(frame2, text = "Yellow",
27 bg = "yellow", variable = self.v1, value = 'Y',
28 command = [Link]) radio button callback
29
30 [Link](row = 1, column = 1)
31 [Link](row = 1, column = 2)
32 [Link](row = 1, column = 3)
33 [Link](row = 1, column = 4)
34 [Link](row = 1, column = 5)
35
36 [Link]() # Create an event loop event loop
37
38 def processRadiobutton(self):
39 if [Link]() == 'R':
40 [Link]["fg"] = "red" set a new fg
41 elif [Link]() == 'Y':
42 [Link]["fg"] = "yellow" set a new fg
43
44 def processButton(self):
45 [Link]["text"] = [Link]() # New text for the label set new text
46
47 ChangeLabelDemo() # Create GUI create GUI
FIGURE 9.5 The program changes the label’s text and fg properties dynamically.
When you select a radio button, the label’s foreground color changes. If you enter new text
in the entry field and click the Change Text button, the new text appears in the label.
The program creates the window (line 5) and invokes its title method to set a title
(line 6). The Frame class is used to create a frame named frame1 and the parent container for
the frame is the window (line 9). This frame is used as the parent container for a label created
in line 11. Because the label is a data field in the class, it can be referenced in a callback
function.
The program creates another frame, frame2 (line 15), for holding a label, an entry, a button,
and two radio buttons. Like frame1, frame2 is placed inside the window.
An entry is created and associated with the variable msg of the StringVar type for storing
the value in the entry (line 19). When you click the Change Text button, the processButton
method sets a new text entry for the label in frame1, using the text in the entry (line 45).
280 Chapter 9 GUI Programming Using Tkinter
Two radio buttons are created and associated with a StringVar variable, v2. v2 is set to
R if the Red radio button is selected, or to Y if the Yellow radio button is clicked. When the user
clicks either of the two buttons, Python invokes the processRadiobutton method to
change the label’s foreground color in frame1 (lines 38–42).
9.6 How do you create a label with the text Welcome, a white foreground, and a red back-
✓
Check
Point
9.7
ground?
How do you create a button with the text OK, a white foreground, a red background,
and with the callback function processOK?
9.8 How do you create a check button with the text apple, a white foreground, a red
background, associated with the variable v1, and with the callback function
processApple?
9.9 How do you create a radio button with the text senior, a white foreground, a red
background, associated with the variable v1, and with the callback function
processSenior?
9.10 How do you create an entry with a white foreground, a red background, and associ-
ated with the variable v1?
9.11 How do you create a message with the text programming is fun, a white fore-
ground, and a red background?
9.12 LEFT, CENTER, and RIGHT are named constants defined in the tkinter module.
Use a print statement to display the values defined by LEFT, CENTER, and
RIGHT.
9.5 Canvas
You use the Canvas widget for displaying shapes.
Key
Point You can use the methods create_rectangle, create_oval, create_arc,
create_polygon, or create_line to draw a rectangle, oval, arc, polygon, or line on a
canvas.
Listing 9.6 shows how to use the Canvas widget. The program displays a rectangle, an
oval, an arc, a polygon, a line, and a text string. The objects are all controlled by buttons, as
shown in Figure 9.6.
LISTING 9.6 [Link]
1 from tkinter import * # Import all definitions from tkinter
2
3 class CanvasDemo:
4 def _ _init_ _(self):
create a window 5 window = Tk() # Create a window
6 [Link]("Canvas Demo") # Set title
7
8 # Place canvas in the window
create a canvas 9 [Link] = Canvas(window, width = 200, height = 100,
10 bg = "white")
11 [Link]()
12
13 # Place buttons in frame
create a frame 14 frame = Frame(window)
15 [Link]()
create buttons 16 btRectangle = Button(frame, text = "Rectangle",
17 command = [Link])
9.5 Canvas 281
18 btOval = Button(frame, text = "Oval",
19 command = [Link])
20 btArc = Button(frame, text = "Arc",
21 command = [Link])
22 btPolygon = Button(frame, text = "Polygon",
23 command = [Link])
24 btLine = Button(frame, text = "Line",
25 command = [Link])
26 btString = Button(frame, text = "String",
27 command = [Link])
28 btClear = Button(frame, text = "Clear",
29 command = [Link])
30 [Link](row = 1, column = 1) place buttons
31 [Link](row = 1, column = 2)
32 [Link](row = 1, column = 3)
33 [Link](row = 1, column = 4)
34 [Link](row = 1, column = 5)
35 [Link](row = 1, column = 6)
36 [Link](row = 1, column = 7)
37
38 [Link]() # Create an event loop event loop
39
40 # Display a rectangle
41 def displayRect(self):
42 [Link].create_rectangle(10, 10, 190, 90, tags = "rect") display rectangle
43
44 # Display an oval
45 def displayOval(self):
46 [Link].create_oval(10, 10, 190, 90, fill = "red", display oval
47 tags = "oval")
48
49 # Display an arc
50 def displayArc(self):
51 [Link].create_arc(10, 10, 190, 90, start = 0, display arc
52 extent = 90, width = 8, fill = "red", tags = "arc")
53
54 # Display a polygon
55 def displayPolygon(self):
56 [Link].create_polygon(10, 10, 190, 90, 30, 50, display polygon
57 tags = "polygon")
58
59 # Display a line
60 def displayLine(self):
61 [Link].create_line(10, 10, 190, 90, fill = "red", display line
62 tags = "line")
63 [Link].create_line(10, 90, 190, 10, width = 9,
64 arrow = "last", activefill = "blue", tags = "line")
65
66 # Display a string
67 def displayString(self):
68 [Link].create_text(60, 40, text = "Hi, I am a string", display string
69 font = "Times 10 bold underline", tags = "string")
70
71 # Clear drawings
72 def clearCanvas(self):
73 [Link]("rect", "oval", "arc", "polygon", clear canvas
74 "line", "string")
75
76 CanvasDemo() # Create GUI create GUI
282 Chapter 9 GUI Programming Using Tkinter
FIGURE 9.6 The geometrical shapes and strings are drawn on the canvas.
The program creates a window (line 5) and sets its title (line 6). A Canvas widget is cre-
ated within the window with a width of 200 pixels, a height of 100 pixels, and a background
color of white (lines 9–10).
Seven buttons—labeled with the text Rectangle, Oval, Arc, Polygon, Line, String, and
grid manager Clear—are created (lines 16–29). The grid manager places the buttons in one row in a frame
(lines 30–36).
To draw graphics, you need to tell the widget where to draw. Each widget has its own
coordinate system coordinate system with the origin (0, 0) at the upper-left corner. The x-coordinate increases to
the right, and the y-coordinate increases downward. Note that the Tkinter coordinate system
differs from the conventional coordinate system, as shown in Figure 9.7.
x
y-axis
(0, 0) x-axis
y
(x, y)
(0, 0) x-axis
Tkinter Conventional
Coordinate Coordinate
System System
y-axis
FIGURE 9.7 The Tkinter coordinate system is measured in pixels, with (0, 0) at its upper-
left corner.
The methods create_rectangle, create_oval, create_arc, create_polygon,
and create_line (lines 42, 46, 51, 56, and 61) are used to draw rectangles, ovals, arcs,
polygons, and lines, as illustrated in Figure 9.8.
create_text The create_text method is used to draw a text string (line 68). Note that the horizontal
and vertical center of the text is displayed at (x, y) for create_text(x, y, text) as
shown in Figure 9.8.
tags All the drawing methods use the tags argument to identify the drawing. These tags are
used in the delete method for clearing the drawing from the canvas (lines 73–74).
9.6 The Geometry Managers 283
extent
(x1, y1) (x1, y1) (x1, y1)
start
(x2, y2) (x2, y2) (x2, y2)
canvas.create_rectangle(x1, y1, x2, y2) canvas.create_oval(x1, y1, x2, y2) canvas.create_arc(x1, y1, x2, y2, start, extent)
(x2, y2) ABCDE
(x1, y1) (x1, y1)
(x2, y2)
(x, y)
(x3, y3)
canvas.create_polygon(x1, y1, x2, y2, x3, y3) canvas.create_line(x1, y1, x2, y2) canvas.create_text(x, y, text = “ABCDE”)
FIGURE 9.8 The Canvas class contains the methods for drawing graphics.
The width argument can be used to specify the pen size in pixels for drawing the shapes width
(lines 52 and 63).
The arrow argument can be used with create_line to draw a line with an arrowhead arrow
(line 64). The arrowhead can appear at the start, end, or both ends of the line with the argu-
ment value first, end, or both.
The activefill argument makes the shape change color when you move the mouse over activefill
it (line 64).
9.13 Write the code to draw a line from (34, 50) to (50, 90).
9.14 Write the code to draw a rectangle centered at (70, 70) with a width of 100 and a
height of 100. Fill the rectangle with the color red.
✓ Check
Point
9.15 Write the code to draw an oval centered at (70, 70) with a width of 200 and a height
of 100. Fill the rectangle with red.
9.16 Write the code to draw an arc with a starting angle of 30, with an extent angle of 45
in a bounding rectangle with its upper-left corner at (10, 10) and bottom-right corner
at (80, 80).
9.17 Write the code to draw a polygon with points at (10, 10), (15, 30), (140, 10), and
(10, 100). Fill the shape with red.
9.18 How do you draw a shape with a large pen size?
9.19 How do you draw a line with an arrowhead?
9.20 How do you make a shape change color when the mouse is moved over it?
9.6 The Geometry Managers
Tkinter uses a geometry manager to place widgets inside a container.
Key
Tkinter supports three geometry managers: the grid manager, the pack manager, and the place Point
manager. You have already used the grid and pack managers. This section describes these
managers and introduces some additional features.
Tip
Since each manager has its own style of placing the widget, it is not a good practice to
mix the managers for the widgets in the same container. You can use a frame as a sub-
container to achieve the desired layout.