-
-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Named widget has NoneType after single line creation #89134
Comments
Declaring a widget in the following form: |
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 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. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: