[Tkinter-discuss] Scroll a table, but not the first two rows?

Russell E. Owen rowen at cesmail.net
Wed May 31 22:27:36 CEST 2006

In article <20060531131858.4df4369e.klappnase at web.de>,
 Michael Lange <klappnase at web.de> wrote:

> On Wed, 31 May 2006 13:06:57 +0200
> Chris Niekel <chris at niekel.net> wrote:
> > On Wed, May 31, 2006 at 02:45:20AM -0700, Mohammad Tayseer wrote:
> > >    Why don't you separate the table from the header? The header should be
> > >    *outside* the ScrolledFrame, so it's not scrolled
> > 
> > Then the grids are different, and the columns are not aligned anymore. Or
> > is there a way to force that?
> > 
> Hi Chris,
> maybe you can calculate the needed width for the header and the associated 
> column and then
> configure both to have the same width. If you bind this method to <Configure> 
> events for
> both the header and the column you should be able to make sure that the width 
> will
> be updated every time the needed width of the column changes.

That's how I manage it. It's rather ugly, but it works. I sure wish 
Tkinter had a nice table widget.

Anyway, here's a code fragment (using bare Tkinter; I don't use pmw). 
The basic architecture (which is a bit weird and perhaps not ideal) is:
- The main widget produces a title frame, the vertical scroll bar and 
the scrolled table.
- The scrolled table is implemented as a widget that not only creates 
the main table, but also fills in the titles in the title frame. The 
code fragment is from this latter widget (and the title frame was passed 
in as an argument to __init___):

    def _addTitle(self, text, col):
        """Create and grid a title label and two associated
        width measuring frames (one in the title frame, one in the main 
        - text  text for title
        - col   column for title
        strWdg = Tkinter.Label(self._titleFrame, text=text)
        strWdg.grid(row=0, column=col)
        titleSpacer = Tkinter.Frame(self._titleFrame)
        titleSpacer.grid(row=1, column=col, sticky="ew")
        mainSpacer = Tkinter.Frame(self)
        mainSpacer.grid(row=2, column=col, sticky="ew")
        def dotitle(evt):
            if titleSpacer.winfo_width() > mainSpacer.winfo_width():
                mainSpacer["width"] = titleSpacer.winfo_width()     
        titleSpacer.bind("<Configure>", dotitle)
        def domain(evt):
            if mainSpacer.winfo_width() > titleSpacer.winfo_width():
                titleSpacer["width"] = mainSpacer.winfo_width()     
        mainSpacer.bind("<Configure>", domain)

To see the whole thing, download TUI source from here
and look at TUI/TUIMenu/Permissions/
(PermisWindow.py imlements the high-level window;
PermisInputWdg.py implements the scrolled table)

More information about the Tkinter-discuss mailing list