The Pack Geometry Manager

We attempt to achieve the same result as shown in the previous screenshot without complete success because pack tries to arrange widgets in a single strip. The limited flexibility pack offers is that it allows us to decide where the strip should begin.

Getting ready

The Pack Layout Manager uses a navigator's compass scheme illustrated as follows:

Getting ready

How to do it...

Execute the program shown in the usual way. The result is shown in the following screenshot:

How to do it...
# pack_button_array_1.py
#>>>>>>>>>>>>>>>>>>>>>>
from Tkinter import *
root = Tk()
root.title("Pack Geometry Manager")
butn_NW = Button(root, bg='blue',text="NorthWest").pack(side=LEFT)
butn_NW1 = Button(root, bg='blue',text="Northwest").pack(side=LEFT)
butn_NE1 = Button(root, bg='blue',text="Northeast").pack(side=LEFT)
butn_NE = Button(root, bg='blue',text="NorthEast").pack(side=LEFT)
butn_N1W = Button(root, bg='sky blue',text="norWest").pack()
butn_N1W1 = Button(root, bg='sky blue',text="norwest").pack()
butn_S1E1 = Button(root, bg='pale green',text="soueast").pack(side=BOTTOM)
Pack Geometry Managerexamplebutn_S1E = Button(root, bg='pale green',text="souEast").pack(side=BOTTOM)
butn_SW = Button(root, bg='green',text="SouthWest").pack(side=RIGHT)
butn_SW1 = Button(root, bg='green',text="SothuWest").pack(side=RIGHT)
butn_SE1 = Button(root, bg='green',text="SouthEast").pack(side=RIGHT)
butn_SE = Button(root, bg='green',text="SouthEast").pack(side=RIGHT)
root.mainloop()

How it works...

The pack geometry packs widgets either in rows or in columns. If we try to do both, the results are difficult to predict as shown in the previous screenshot.

What it does is it starts at one edge, which you may specify, and then just lays the widgets one-by-one next to each other in the same order that they appear in our code. If you do not specify an edge to start on the default is TOP so the widgets will be laid out as a single column.

There are also parameters that specify whether the widget should be padded out to fill available space. We can get this detail from:

http://effbot.org/tkinterbook/pack.htm

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.129.253