israel-dryer / ttkbootstrap

A supercharged theme extension for tkinter that enables on-demand modern flat style themes inspired by Bootstrap.
MIT License
1.96k stars 389 forks source link

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

Open QingyuFeng opened 5 months ago

QingyuFeng commented 5 months ago

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

1337haxx0r commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 =)