Mailing List Archive

Book -- or website -- about Tk & tkinter
Can anyone recommend a good book or website that explains how Tk does
its geometry management (the grid, pack etc managers)?

I'd be particularly interested in anything that talks in terms of
tkinter.

--
Phil Hunt....philh@vision25.demon.co.uk
Book -- or website -- about Tk & tkinter [ In reply to ]
Phil Hunt wrote:
>
> Can anyone recommend a good book or website that explains how Tk does
> its geometry management (the grid, pack etc managers)?

Do you mean the low level nuts and bolts, or just how to use the
managers effectively? Brent Welch's _Practical Programming in Tcl and
Tk_ is the best book I've seen at the local bookstore, which isn't
saying much. At least 300 of the 400 pages deal with Tk, and he does
have some good hints and examples on building up a GUI with frames.

Many of the concepts are similar to Java, so any of the Java GUI
tutorials might be useful, or, since Tk was a veneer on the X toolkit,
some of the X docs. The basic concept is the old divide and conquer
technique. You can stuff a couple of widgets into a frame and get them
to behave. Then you put that frame into another frame, and deal with
that layer of siblings, and so forth.

As far as tkinter, read the life preserver, Fredrik Lundh's in progress
work, and the code in the Demo and Tools packages. Mostly, I'm afraid,
read between the lines, and experiment.
--
Bear Technology Making Montana safe for Grizzlies

http://people.montana.com/~bowman/
Book -- or website -- about Tk & tkinter [ In reply to ]
In article <37BE30BA.E45BB293@montana.com> bowman@montana.com "bowman" writes:
> Phil Hunt wrote:
> >
> > Can anyone recommend a good book or website that explains how Tk does
> > its geometry management (the grid, pack etc managers)?
>
> Do you mean the low level nuts and bolts, or just how to use the
> managers effectively?

I want to know enough to write a Python/tkinter backend for my
Parrot GUI builder. So I'd guess I'd need to know some of the nuts
and bolts.

> Many of the concepts are similar to Java, so any of the Java GUI
> tutorials might be useful,

Ah yes, Java's GridBagLayout widget. It was this, and IBM's
Visual Age visual composition tool, that provided the main
inspiration for Parrot -- on the grounds that ``there must be
a better way than this''.

> As far as tkinter, read the life preserver, Fredrik Lundh's in progress
> work, and the code in the Demo and Tools packages. Mostly, I'm afraid,
> read between the lines, and experiment.

Is the Lif Preserver still useful? Lundh's _An Introduction to
Tkinter_ says it's a replacement for it.

But you're right -- experimentation will no doubt be necessary.

--
Phil Hunt....philh@vision25.demon.co.uk
Book -- or website -- about Tk & tkinter [ In reply to ]
Phil Hunt wrote:
>
> Is the Lif Preserver still useful? Lundh's _An Introduction to
> Tkinter_ says it's a replacement for it.

I use a local copy of LifePreserver as a quick reference, and have a
Netscape button aimed at it. I have the Intro as a ps file, but
ghostview doesn't really make my day.

I'm sure Lundh work will be a replacement someday, but that is then...
Right now, it seems the areas I'm interested in are largely TODOs.
Menus, for instance.

> But you're right -- experimentation will no doubt be necessary.

I'm mostly faking it, working from Tcl/Tk, PerlTk, Motif, X docs, and
prior experience with Java and MS Windows programming in C. Essentially,
I'm trying to develop a Tkinter style that is consistent with what I do
in other languages. This sometimes leads me to interesting (to me)
tricks. I'm used to using pretty much anonymous widgets, and determining
their identity in the callbacks, leading to hacks like:

for b in ('one', 'two', 'three'):
b = Button(parent, text=b)
b['command'] = lambda wid=b : (someFunc(wid))
b.pack(side=LEFT)

Its real easy to whip up a Tkinter GUI for a specific set of widgets,
which is what most of the examples do. Trying to use another level of
generalization, say if you want to generate a GUI from something like a
uil or rc file, or in your case, Parrot, requires a little more work.

> Ah yes, Java's GridBagLayout widget.

Yeah, wondrous thing, that. In Java, I tend to set the layout manager to
null and do absolute positioning. Or, I should say, I calculate the
positions and then place things, effectively writing my own manager.
Moot point. It gets ugly, especially with text, where you need to get
the TextMetrics, or whatever the local Java/Windows/Xt word for it is.
There is no free lunch, though, and someplace, somewhere, somebody is
doing the math. At least if you do it yourself, there are no surprises
-- or you can fix your own little surprises.

You might want to take a look at place(), too. The relative positioning
isn't real intuitive, but it sometimes helps to place a widget at 33% of
the width of the parent, no matter what happens to the parent.


--
Bear Technology Making Montana safe for Grizzlies

http://people.montana.com/~bowman/