Tkinter layout manager methods

Richard Brodie R.Brodie at rl.ac.uk
Thu Aug 3 08:59:47 EDT 2000


"Hans-Joachim Widmaier" <hjwidmai at foxboro.com> wrote in message
news:20000803135555.A31004 at foxboro.com...
> Why do the layout manager methods of widgets not return a reference to
> the widget?
>
> Example:
>
>     b = Button(text="Ok", command=self.ok)
>     b.pack()
>
> I'd rather write:
>
> b = Button(text="Ok", command=self.ok).pack()
>
> Since python is well thought out, there might be a reason for this.
> I just don't see it.

Consistency with other operators I guess. For example, list.sort() doesn't
return anything; neither are assignments expressions.

Writing as someone almost completely ignorant of Tk, the second line
looks more obscure. I'm happy with:

 Button b = Button(text="Ok", command=self.ok).pack()

in a strongly typed language. Then it's clear that b ends up as an
instance of Button.

There is always the option of combining the statements on one line
which, used sparingly, can make the code easier to follow.

e.g. b = Button(text="Ok", command=self.ok); b.pack()

Easier to read, and only slightly harder to write IMHO.

With-lines-200-characters-wide-you-can-fit-multiple-statements-on-
one-line'ly-yours.

Richard Brodie.





More information about the Python-list mailing list