-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
tkinter.ttk._val_or_dict assumes tkinter._default_root exists #65601
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
Comments
If a call is made to tkinter.NoDefaultRoot, then calls to tkinter.ttk._val_or_dict may fail. NoDefaultRoot ends with "del _default_root" (line 174) and removes the variable from the module's namespace. _val_or_dict can try to access this variable but assumes that it exists (line 319). If _default_root does not exist, the function will raise an AttributeError: 'module' object has no attribute '_default_root'. |
Can you provide an example of when this happens? Note that tkinter.ttk._val_or_dict is a private function and should not be called by user code. |
I discovered the problem when trying to run the program listed at |
A reference to a non-existent attribute fails no matter who calls the function. Stephen, can you suggest a patch, perhaps based on code in other functions that try to access _default_root? |
It seems that most functions and methods do not bother checking if _default_root exists before trying to access it. However, upon seeing line 366 in ttk (if tkinter._support_default_root:), my recommendation would be to change line 319 to "if tkinter._support_default_root and tkinter._default_root:" to fix the problem. Several similar lines appear in tkinter\init.py at locations 1835, 1845, and 2050. |
This is not so easy, because it does not work with wantobject=False and can not work with future versions of Tk. Actually we should use self.tk instead of _default_root, but this will change the signature of _list_from_layouttuple() and _val_or_dict(). Due to the risk of breaking existing user code which uses these private functions, they should be left with old signature and new functions should be added. |
There is discussion of removing wantobjects in bpo-3015. If it gets removed, a better patch might be created for future versions of tkinter. However, accessing self.tk would probably be a good replacement for anywhere tkinter._default_root can be found (except in cases where a widget is not given a parent). |
The reason we make things private is so we don't have to do this. Why would you make an exception here? |
Because there are explicit tests for these private functions. |
Does that not mean that both the functions and their explicit tests should be changed? |
Well, if we allow to change signature of theses functions, here is a patch which fixes _list_from_layouttuple and _val_or_dict and rewrites tests. Mocked TkApp is used because test_functions should run without the gui resource enabled. |
New changeset 8e5c65719c12 by Serhiy Storchaka in branch '2.7': New changeset 4a0987b8f630 by Serhiy Storchaka in branch '3.4': New changeset c112a91ad609 by Serhiy Storchaka in branch 'default': |
Thank you for your report Stephen. |
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: