Suprabhat Khot
Suprabhat Khot

Reputation: 3

Why do I get tkinter.TclError: bitmap not defined error?

from tkinter import *
from configparser import ConfigParser
from tkinter import messagebox
import requests

if weather:
    location_lbl['text'] = '{}, {}'.format(weather[0], weather[1])
    image_lbl['bitmap'] = 'icons/{}.png'.format(weather[4])
    temp_lbl['text'] = '{:.2f}°C, {:.2f}°F'.format(weather[2], weather[3])
    weather_lbl['text'] = weather[5]

I got this error:

_tkinter.TclError: bitmap "icons/50d.png" not defined

Please help me.

Upvotes: 0

Views: 1135

Answers (1)

Delrius Euphoria
Delrius Euphoria

Reputation: 15098

This is a misunderstanding, image_lbl['bitmap'] is NOT used for showing png files or your loaded image files, its more like for showing the bitmaps loaded into tkinter:

image_lbl['bitmap'] = 'error' #or questionhead, warning, gray50, etc.

If you want to load a png image then use tk.PhotoImage, like:

img = tk.PhotoImage(file='icons/{}.png'.format(weather[4]))
image_lbl['image'] = img

Though its worth noting that for using jpeg, an additional module named PIL has to be used.

Take a look at these, helpful links:

Bitmaps on tkinter

PhotoImage on tkinter

Upvotes: 1

Related Questions