Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:
I'm sorry if you don't like the design of the pack() method, but all the examples in the documentation show how it behaves. It is behaving as documented and designed. https://docs.python.org/3/library/tkinter.html The bug here is in your own code. You already know the correct way to write this, as you already stated: label2 = ttk.Label(root, text='Show2 Label') label2.pack() Writing it as ttk.Label(root, text='Show2 Label').pack() returns None, as designed, which then consequently fails when you try to operate on None. You say: "If giving a widget a name, I expect to use it later in the program." But you don't give the widget a name. What you are doing is the equivalent of this: temp = ttk.Label(root, text='Show2 Label') # hidden temp object label = temp.pack() # Returns None del temp # hidden temp object is garbage collected except that `temp` is never directly accessible by you. Or if you prefer another analogy: number = (1 + 2) - 3 and then get surprised that number is zero rather than 3 because "I gave (1+2) a name". No, you gave a name to the *whole expression*, which evaluates to 0, not 3. And in the Label case, the *whole expression* evaluates to None. Also, the code doesn't crash. It raises an exception, which is the expected behaviour for trying to access non-existent attributes. ---------- nosy: +steven.daprano resolution: -> not a bug stage: -> resolved status: open -> closed type: crash -> behavior _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue44971> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com