Python 2.7 TKINTER库中的图像错误

发布于 2025-02-08 08:01:17 字数 762 浏览 1 评论 0原文

我使用Python 2.7与TKINTER创建图形接口(对于ArcGIS脚本),但是当我想将壁纸加载到接口中时,它会给我错误 “ _tkinter.tclerror:无法在图像文件[图像路径]中识别数据” 我在互联网上搜索了各种解决方案,最好的解决方案是PIL库。 找不到其他解决方案? 以下是书面代码。谢谢

from Tkinter import * 
import os

ROOT_PATH = os.getcwd()
window = Tk()
window.title("Update TXT field")
window.geometry("950x350")
window.config(bg = "white")

canvas = Canvas(window, width = 900, height = 350, bg = "white")
canvas.grid(row = 0, column = 1)


img = PhotoImage(file=os.path.join(ROOT_PATH, "logo.png"))
image = canvas.create_image(861,320, image=img)
canvas.pack()

label_path = Label(text = "Add path to folder:")
label_path.grid(row = 1, column = 0)

path_entry = Entry(width = 35)
path_entry.grid(row = 1, column = 1)

button = Button()

window.mainloop()

I use python 2.7 to create a graphical interface with Tkinter (for an arcgis script) but when I want to load wallpaper in the interface, it gives me the error
"_tkinter.TclError: could not recognize data in image file [path to image]"
I searched the internet for various solutions and the best one would be with the PIL library.
Can't find another solution?
Below is the written code. Thanks

from Tkinter import * 
import os

ROOT_PATH = os.getcwd()
window = Tk()
window.title("Update TXT field")
window.geometry("950x350")
window.config(bg = "white")

canvas = Canvas(window, width = 900, height = 350, bg = "white")
canvas.grid(row = 0, column = 1)


img = PhotoImage(file=os.path.join(ROOT_PATH, "logo.png"))
image = canvas.create_image(861,320, image=img)
canvas.pack()

label_path = Label(text = "Add path to folder:")
label_path.grid(row = 1, column = 0)

path_entry = Entry(width = 35)
path_entry.grid(row = 1, column = 1)

button = Button()

window.mainloop()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文