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.

classification
Title: _tkinter.TclError: expected boolean value but got ""
Type: crash Stage: resolved
Components: macOS, Tkinter Versions: Python 3.8
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: amin-nejad, epaine, ned.deily, ronaldoussoren, serhiy.storchaka, terry.reedy
Priority: normal Keywords:

Created on 2021-12-01 21:54 by amin-nejad, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (12)
msg407494 - (view) Author: Ali Amin-Nejad (amin-nejad) Date: 2021-12-01 21:54
On macOS, the following minimal example:

```
import tkinter as tk

root = tk.Tk()
button = tk.Button(root, text="Exit", command=root.destroy)
button.pack()
root.wm_overrideredirect(True)

root.mainloop()
```

yields the following stack trace:

```
Traceback (most recent call last):
  File "blah.py", line 6, in <module>
    root.wm_overrideredirect(True)
  File "/Users/ali/miniconda3/envs/bitfount/lib/python3.8/tkinter/__init__.py", line 2176, in wm_overrideredirect
    return self._getboolean(self.tk.call(
  File "/Users/ali/miniconda3/envs/bitfount/lib/python3.8/tkinter/__init__.py", line 1448, in _getboolean
    return self.tk.getboolean(string)
_tkinter.TclError: expected boolean value but got ""
```
msg407517 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-12-02 09:09
What is the result of

   root.tk.call('wm', 'overrideredirect', root._w, True)

?

Is it not an empty string?
msg407543 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2021-12-02 19:27
I am not able to reproduce this failure with various macOS Pythons from python.org that are built with either Tk 8.6.8 or 8.6.12. Perhaps it's an issue with the Tk provided with your Miniconda Python?  Besides answering Serhiy's question, it would be helpful to know the exact patch level of Tk that is being used and also the path to the Tk library.

The output from

/path/to/your/python -m test.pythoninfo

and

otool -L $(/path/to/your/python -c "import _tkinter;print(_tkinter.__file__)")

will give those answers.
msg407549 - (view) Author: Ali Amin-Nejad (amin-nejad) Date: 2021-12-02 22:16
@serhiy.storchaka I tried that command, the returned value is not an empty string, it is an object of type <class '_tkinter.Tcl_Obj'>. However including that line in my script immediately after creating the `root` object actually fixes the problem - no more error and the button appears and is responsive.

@ned.deily I am on tkinter 8.6.11. The output from the second command is:

```
/Users/ali/miniconda3/envs/bitfount/lib/python3.8/lib-dynload/_tkinter.cpython-38-darwin.so:
        @rpath/libtcl8.6.dylib (compatibility version 8.6.0, current version 8.6.11)
        @rpath/libtk8.6.dylib (compatibility version 8.6.0, current version 8.6.11)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)
```

I have just tried the same script in a separate python 3.9 environment with python 3.9.6 and tkinter 8.6.10 and the error is not there so it seems like it is introduced in 8.6.11. Happy to try on 8.6.12 but I'm not sure how to upgrade to it.
msg407552 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-12-02 22:40
Thank you Ali. It confirms my guess, but it is still not clear why we get a Tcl_Obj rather of None or empty string.

Please examine what is the output of the following code:

res = root.tk.call('wm', 'overrideredirect', root._w, True)
print([res.typename])
print([res.string])

If the first print crashes comment out it.
msg407557 - (view) Author: Ali Amin-Nejad (amin-nejad) Date: 2021-12-02 23:24
Thanks Serhiy, the output is:

['StateSpec']
['']
msg407584 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-12-03 13:06
It looks like a bug in Tk 8.6.11. It is expected that the implementation of "wm overrideredirect" returns an empty string if pass the boolean argument. The returned value is an empty string, but its type is not cleared. Seems it keeps the type of previous result.

I think that we can add a workaround for this bug, although it may be inconvenient to test it. Do we still use Tk 8.6.11 on any platform with Python 3.9+? Note that Python 3.8 only takes security fixes, so any changes can only be made in 3.9+.
msg407585 - (view) Author: E. Paine (epaine) * Date: 2021-12-03 13:24
> Do we still use Tk 8.6.11 on any platform with Python 3.9+

No, none of the python.org installers include it now. On Linux, according to https://pkgs.org/download/tk, several distros still use 8.6.11 (most notably Ubuntu 21.04). I'll see if I can reproduce it on Linux using 8.6.11 and then we can decide whether or not a workaround is required.
msg407815 - (view) Author: E. Paine (epaine) * Date: 2021-12-06 14:31
I cannot reproduce on Ubuntu 21.10 (Tk 8.6.11), so I believe we can close this issue.
msg407859 - (view) Author: Ali Amin-Nejad (amin-nejad) Date: 2021-12-06 19:44
It seems like it must be a mac-specific issue just on 8.6.11 then if ned couldn't reproduce on 8.6.12. How does one go about upgrading their tkinter version? Thanks
msg407860 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2021-12-06 20:13
> How does one go about upgrading their tkinter version?

Since, based on your path names, you appear to be using a Python from miniconda, you should check with that project. Perhaps they have a newer version available. Good luck!
msg407870 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-12-06 22:13
Or use python.org installer ;-).
History
Date User Action Args
2022-04-11 14:59:53adminsetgithub: 90115
2021-12-06 22:13:50terry.reedysetmessages: + msg407870
2021-12-06 20:13:33ned.deilysetstatus: open -> closed
resolution: out of date
messages: + msg407860

stage: resolved
2021-12-06 19:44:44amin-nejadsetmessages: + msg407859
2021-12-06 14:31:40epainesettype: behavior -> crash
messages: + msg407815
2021-12-03 13:24:12epainesetmessages: + msg407585
2021-12-03 13:17:20AlexWaygoodsettype: crash -> behavior
2021-12-03 13:06:13serhiy.storchakasetnosy: + terry.reedy, epaine
messages: + msg407584
2021-12-02 23:24:42amin-nejadsetmessages: + msg407557
2021-12-02 22:40:18serhiy.storchakasetmessages: + msg407552
2021-12-02 22:16:46amin-nejadsetmessages: + msg407549
2021-12-02 19:27:33ned.deilysetmessages: + msg407543
2021-12-02 09:09:40serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg407517
2021-12-01 21:54:38amin-nejadcreate