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

Francesco Bochicchio bockman at virgilio.it
Sun Feb 17 03:29:50 EST 2008


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

> from Tkinter import *
> 
> class App:
>      def __init__(self, master):
>          fm = Frame(master)
>          Button(fm, text='Left').pack(side=LEFT)
>          Button(fm, text='This is the Center button').pack(side=LEFT)
>          Button(fm, text='Right').pack(side=LEFT)
>          fm.pack()
> 
> root = Tk()
> root.option_add('*font', ('verdana', 12, 'bold'))
> root.title("Pack - Example 2")
> display = App(root)
> root.mainloop()

The obvious question is: why don't you run both and see what happens?

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.

Ciao
-----
FB



More information about the Python-list mailing list