Skip to content
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

_tkinter.TclError: couldn't recognize image data #584

Open
QingyuFeng opened this issue Jun 8, 2024 · 4 comments
Open

_tkinter.TclError: couldn't recognize image data #584

QingyuFeng opened this issue Jun 8, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@QingyuFeng
Copy link

Desktop (please complete the following information):

ttkbootstrap version: 1.10.1
OS: Macos sonoma 14.5
python version: 3.9.6

Describe the bug

I was trying to develop an app with ttkbootstrap. However, when I was testing the package, it worked pretty on windows 10. But, when I was trying it on Macos, an error occurred. I created a virtual environment using the Macos default python version, and try to run the text reader demo (https://ttkbootstrap.readthedocs.io/en/latest/gallery/textreader/), it is not working. I checked online and found it was a common error with PhotoImage.

To Reproduce

DEPRECATION WARNING: The system version of Tk is deprecated and may be removed in a future release. Please don't rely on it. Set TK_SILENCE_DEPRECATION=1 to suppress this warning.
Traceback (most recent call last):
File "/Users/fengqingyu/Documents/appDevMaster/emc_ecoevalt/src/test_notebook.py", line 47, in
app = ttk.Window("Text Reader", "sandstone")
File "/Users/fengqingyu/Documents/appDevMaster/emc_ecoevalt/env/lib/python3.9/site-packages/ttkbootstrap/window.py", line 231, in init
self._icon = tkinter.PhotoImage(master=self, data=Icon.icon)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/tkinter/init.py", line 4064, in init
Image.init(self, 'photo', name, cnf, master, **kw)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/tkinter/init.py", line 4009, in init
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize image data

Expected behavior

No response

Screenshots

No response

Additional context

No response

@QingyuFeng QingyuFeng added the bug Something isn't working label Jun 8, 2024
@1337haxx0r
Copy link

1337haxx0r commented Jul 22, 2024

Yup, same issue here.
Possibly any solutions?

Traceback (most recent call last):
File "/Users/{user}/Documents/{app}/main.py", line 472, in
root = ttk.Window(themename="journal") # Create a new window with the "journal" theme
File "/Users/{user}/Documents/{app}/venv/lib/python3.9/site-packages/ttkbootstrap/window.py", line 231, in init
self._icon = tkinter.PhotoImage(master=self, data=Icon.icon)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/tkinter/init.py", line 4064, in init
Image.init(self, 'photo', name, cnf, master, **kw)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/tkinter/init.py", line 4009, in init
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize image data

It works on Win10, as well

@rdbende
Copy link

rdbende commented Jul 22, 2024

The version of tkinter provided in macOS is probably outdated. If the following code:

import tkinter
print(tkinter.TkVersion)

gives anything below 8.6, you should update it somehow. There instructions on it on the internet.

@1337haxx0r
Copy link

The version of tkinter provided in macOS is probably outdated. If the following code:

import tkinter
print(tkinter.TkVersion)

gives anything below 8.6, you should update it somehow. There instructions on it on the internet.

Appreciate your response. indeed, it is 8.5. I'll work on updating it

@1337haxx0r
Copy link

1337haxx0r commented Jul 22, 2024

Alright.
So I did update tkinter to 8.6 following this answer: https://stackoverflow.com/a/61879759

Done these steps:

brew install tcl-tk
export PATH="/usr/local/opt/tcl-tk/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/tcl-tk/lib"
export CPPFLAGS="-I/usr/local/opt/tcl-tk/include"
export PKG_CONFIG_PATH="/usr/local/opt/tcl-tk/lib/pkgconfig"
brew reinstall python

make sure version is updated:

brew info tcl-tk

Then created new environment

python3 -m venv myenv

Activate it

source myenv/bin/activate

and run the *.py test file with:

import tkinter
print(tkinter.TkVersion)

So, I moved my projects files into the new environment and issue with not recognizing image data was solved.
Thank you @rdbende for showing which way to dig =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants