简体   繁体   English

为什么我得到 tkinter.TclError: bitmap not defined 错误?

[英]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:看看这些有用的链接:

Bitmaps on tkinter tkinter 上的位图

PhotoImage on tkinter tkinter 上的 PhotoImage

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 _tkinter.TclError:未定义位图“ pyimage2” - _tkinter.TclError: bitmap “pyimage2” not defined _tkinter.TclError:位图数据中的格式错误 - _tkinter.TclError: format error in bitmap data _tkinter.TclError: bitmap "icon.ico" 未定义 - _tkinter.TclError: bitmap "icon.ico" not defined _tkinter.TclError:读取 bitmap 文件“logo.ico”时出错 - _tkinter.TclError: error reading bitmap file “logo.ico” 尝试创建位图时:_tkinter.TclError: bitmap "pyimage2" not defined - when trying to create a bitmap: _tkinter.TclError: bitmap "pyimage2" not defined 为什么在尝试获取文本小部件的内容时收到 tkinter.TclError? - Why am I receiving a tkinter.TclError when trying to get the content of a text widget? 我在销毁按钮时收到错误 _tkinter.TclError: bad window path name “.!button” - I get the error _tkinter.TclError: bad window path name “.!button” when I destroy the button Tkinter -tkinter.TclError - Tkinter -tkinter.TclError 当我在 python 中运行我的刽子手游戏时出现此错误:_tkinter.TclError:命令名称“.!canvas”无效 - i get this error when I am running my hangman game in python: _tkinter.TclError: invalid command name ".!canvas" Tkinter 错误(_tkinter.TclError:预期整数但得到“Serif”) - Tkinter error (_tkinter.TclError: expected integer but got "Serif")
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM