I am trying to receive information from an API. My problem is that i keep getting an error like this : _tkinter.TclError: bitmap "weather_icons/04n.png" not defined
A part of the code is here .... would appreciate if somebody can enlighten me because i tryed to move the pictures from the "weather_icons" folder into the main folder , doesn't work, i tryed to use .gif instead of .png, doesn't work....
if weather:
location_lbl["text"] = "{}, {}".format(weather[0], weather[1])
image["bitmap"] = "weather_icons/{}.png".format(weather[4])
temp_lbl["text"] = "{:.2f}°C, {:.2f}°F".format(weather[2], weather[3])
weather_lbl["text"] = weather[5]
else:
messagebox.showerror("Error", "Can't find city {}".format(city))
Line 3 gives me that error.
It seems to me that there are (at least) two potential problems here.
The first (and the most likely) is the location of your graphic (
png
) file. If your working directory is not the one containing theweather_icons
directory, it won't find it. You can check this by doing something like:and seeing if you're in the correct directory and the file exists.
To fix that, you'll either have to make sure your working directory is as expected, or find a way to generate an absolute path to the graphic file.
Secondly, it may be the file format is not supported by the
image
type (less likely, but since you haven't shown the creation of that variable, it's unclear at the moment what it is - that's something you may want to add to the question), or that the graphic file itself is corrupted.You have rightly stated that you've also tried it with a
gif
file, and I assume that was a realgif
, not just renaming thepng
file. In any case, you may want to try a very simple set of other image files to confirm.