Cannot achieve padding with Tkinter "grid" [column,row]configure()"

Steve Holden sholden at holdenweb.com
Thu Aug 24 10:27:15 EDT 2000


I'm just starting to get to grips with Tkinter GUI's, and have managed
to produce a somewhat usable prototype interface for a mail search
program I'm working on.  But no matter what I try, I just can't seem
to get the grid cells to pad.  Everything is jammed together in the
window!

The relevant sections of the code are extracted below.  Sorry if my
mailer wraps the code.  Can anyone explain my dumb error?

I've looked for information on this topic in the effbot's notes from
the pythonware site, and Grayson's "Python and Tkinter Programming".
If there are better (or even simply other) references around I would
appreciate pointers.

regards
Steve Holden
------------------------ Code extracts begin -----------------------
from Tkinter import *
import Pmw
import os
import DBSubject
import string
import sys
import mimecntl

#
# XXX remove all flush() calls (and debug printing?)
#
# Globals
#
DEBUG = []
INTERVAL = 250                      # milliseconds between examinations
NOTFOUND = -1                       # indicator for no such item

class MailSearch(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.grid(sticky=N+E+W+S)
        for i in range(2):
            self.columnconfigure(i, weight=1, pad=40)
        for i in [3,4]:
            self.rowconfigure(i, weight=1, pad=40)
        self.createSearch()
        self.createButtons()
        try:
            self.index = DBSubject.SubIndex()
        except:
            print "Could not open database."
            sys.exit(-1)
        self.after(INTERVAL, self.checkText)
        self.sWords = []    # words in search text box
        self.sSet = []     # matching words from database
        self.sSel = []     # numbers of selected words
        self.Selection = ()
        self.cWord = NOTFOUND
        self.sTxt.focus()

    def createSearch(self):
        Label(self, text='Subject words:').grid(row=0, column=0, sticky=N+W)
        t = self.sTxt = Entry(self)
        t.grid(row=1, column=0, sticky=W+E)
        Label(self, text='Select desired words:').grid(row=2, column=0,
sticky=W)
        self.wLst = Pmw.ScrolledListBox(self,
                        listbox_selectmode=EXTENDED,
                        listbox_exportselection=0,
                        vscrollmode='static',
                        hscrollmode='none')
        self.wLst.grid(row=3, column=0, sticky=N+E+W+S)
        Label(self, text="Subjects containing those words:").grid(row=0,
column=1, sticky=N+W)
        self.sLst = Pmw.ScrolledListBox(self,
                        listbox_exportselection=0,
                        vscrollmode='static',
                        hscrollmode='none',
                        selectioncommand=self.listMessages)
        self.sLst.grid(row=1, rowspan=3, column=1, sticky=N+E+W+S)
        self.msgList = Pmw.ScrolledListBox(self,
                        listbox_exportselection=0,
                        dblclickcommand=self.showMessage,
                        vscrollmode='static',
                        hscrollmode='none')
        self.msgList.grid(row=4, column=0, columnspan=3, sticky=N+E+W+S)


    def createButtons(self):
        self.xBtn = Button(self, text="Close", width=10,  command=self.close)
        self.xBtn.grid(row=0, column=2, sticky=N)

	[Irrelevant database code, callbacks, etc., all snipped]

if __name__ == "__main__":
    root = Pmw.initialise()
    root.grid()
    root.columnconfigure(0, weight=1)
    root.rowconfigure(0, weight=1)
    ddnotebook = MailSearch(root)
    ddnotebook.mainloop()


-- 
Helping people meet their information needs with training and technology.
703 967 0887      sholden at bellatlantic.net      http://www.holdenweb.com/



More information about the Python-list mailing list