Tkinter grid layout

Richard Lewis richardlewis at fastmail.co.uk
Wed Jul 6 06:44:55 EDT 2005


Hi there,

I've got a tree control in Tkinter (using the ESRF Tree module) but I
can't get it to layout how I want it.

I'd like to have it so that it streches north/south (anchored to the top
and bottom), is of a fixed width and is anchored to the left hand side.
Here's my code (its derived from one of the examples from the ESRF web
site):

class MainWindow(Frame):
  def __init__(self, master):
    Frame.__init__(self, master)
    self.document = # new DOM document
    self.create_site_list()
  
  def create_site_list(self):
    self.list_model = ListModel(self.document)
    # ListModel class returns the DOM outline as a simple Python data
    structure

    self.site_list = Tree.Tree(master=self,\
        root_id="root",\
        root_label="Site",\
        get_contents_callback=self.get_list_item,\
         # get_list_item uses the list_model to build list nodes
        width=300)

    self.site_list.grid(row=0, column=0, sticky=N+SW)

    self.grid_rowconfigure(0, weight=1)

    vsb = Scrollbar(self, orient=VERTICAL)
    vsb.grid(row=0, column=1, sticky=NS)
    self.site_list.configure(yscrollcommand=vsb.set)
    vsb.configure(command=self.site_list.yview)

    hsb = Scrollbar(self, orient=HORIZONTAL)
    hsb.grid(row=1, column=0, sticky=EW+S)
    self.site_list.configure(xscrollcommand=hsb.set)
    hsb.configure(command=self.site_list.xview)

    self.site_list.focus_set()


This code makes it centred in the east/west direction and a constant
height anchored to the top. I guess its the sticky values I need to play
with (?) but I can't find the right combination. I've given the code
with the ones that seem logically correct (to me!)

I expect this is probably quite trivial for someone who knows what
they're doing.

Any ideas?

Cheers,
Richard



More information about the Python-list mailing list