[英]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.请帮我。
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']
不用于显示 png 文件或加载的图像文件,它更像是用于显示加载到 tkinter 中的位图:
image_lbl['bitmap'] = 'error' #or questionhead, warning, gray50, etc.
If you want to load a png image then use tk.PhotoImage
, like:如果要加载 png 图像,请使用tk.PhotoImage
,例如:
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.尽管值得注意的是,为了使用jpeg
,必须使用一个名为PIL
的附加模块。
Take a look at these, helpful links:看看这些有用的链接:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.