Terry J. Reedy <[email protected]> added the comment:
1. (Josh beat me here.) One of Python's design features is that stdlib
functions/methods that mutate (or register) an object never (as far as I can
remember) return the object. (If they return anything other than None, it is
something other than the object. List.pop returns a member, not the list.)
Changing this rule either in particular cases or in general has been rejected
by Guido multiple times. A new proposal for particular exceptions would have
to be approved by the still-in-the-future new design decision process. It
would likely start with posting to python-ideas list.
Consistency of this rule is a feature. If people got used to writing 'item =
Widget(...).geo_manager(...)', they would more often make the mistake of
writing buggy code like 'items = lister().sort()'
2. (Based on experience with IDLE.) The toy example with 3 one-line statements
creating 3 blank Labels admittedly looks nice and neat. And in such
situations, can actually get close today.
label1 = tk.Label(root); label1.grid(row=0, column=0)
label2 = tk.Label(root); label2.grid(row=0, column=1)
label3 = tk.Label(root); label3.grid(row=0, column=2)
However, in real situations, the widget creation statement is often or usually
in the body of a class method and starts with at least an 8 space indent. The
call nearly always has a content argument and often other configuration
arguments. Such statements often require more than one line even without the
manager call added. Manager calls may also have additional arguments. The
result is ragged code and if manager calls are appended, they are not so easy
to pick out.
I believe a majority of experienced tkinter users prefer a style omitted from
the opening example: create a batch of widgets; then lay them out. The
following untested example shows the idea. It keeps the row and column numbers
close together and includes parent grid calls in the layout section.
class Viewframe(Frame):
def __init__(self, parent, ...)
...
self.populate()
def populate(self):
label = Label(self, text='hello world', ...)
button = Button(self, text='press me), command=lambda: <do something>)
text = Text(self, ...)
label.grid(row=0, column=0)
button.grid(row=1, column=0)
text.grid(row=0, column=1, rowspan=2, sticky='NSEW')
self.columnconfigure(column=1, weight=1)
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue35700>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com