Tkinter. Why the Need for a Frame, or no Frame?

petercable at gmail.com petercable at gmail.com
Sun Feb 17 06:46:39 EST 2008


On Feb 17, 9:29 am, Francesco Bochicchio <bock... at virgilio.it> wrote:

>
> Anyway, Tk() already opens a frame, so in the first example the buttons
> are created inside that frame, while in the second example two frames
> are created: the one creaded by Tk() il left empty but you should see it
> (maybe very small in a corner) if you run the program.

The container returned by Tk() (root) is passed into App and the frame
inside App (fm) is packed into it. It's not left empty and you won't
ever see it.

On Sat, 16 Feb 2008 19:40:51 -0800, W. Watson wrote:

> The following two examples are from Grayson's book on Tkinter. He's
> making a simple dialog with three buttons. In the first example, he
> does not use the Frame class, but in the second he does. Doesn't the
> first example need a container? What's the difference here?

For simple Tk applications, it's not necessary to create Frames to
pack inside the root container. However, more complicated GUIs will
often include multiple nested frames. Because each container can only
be managed by one geometry manager, multiple containers are the only
way to create complex interfaces.

Anyway, the answer is, it's not necessary to create a Frame in the
first example, as the initial call to Tkinter.Tk() will return the
root container, which can be used to pack any widget. In the first
example, the three buttons are packed directly into the root
container. In the second example, the three buttons are packed into a
frame which is in turn packed into the root container.

Happy to help,

Pete Cable
(formerly of Yuba City, CA)



More information about the Python-list mailing list