This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients Epyxoid, gpolo, josh.r, serhiy.storchaka, terry.reedy, zach.ware
Date 2019-01-09.19:20:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1547061642.3.0.0318078333587.issue35700@roundup.psfhosted.org>
In-reply-to
Content
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)
History
Date User Action Args
2019-01-09 19:20:44terry.reedysetrecipients: + terry.reedy, gpolo, zach.ware, serhiy.storchaka, josh.r, Epyxoid
2019-01-09 19:20:42terry.reedysetmessageid: <1547061642.3.0.0318078333587.issue35700@roundup.psfhosted.org>
2019-01-09 19:20:42terry.reedylinkissue35700 messages
2019-01-09 19:20:42terry.reedycreate