【问题标题】:Is there a way for me to upload an image on tkinter without using PIL?有没有办法让我在不使用 PIL 的情况下在 tkinter 上上传图像?
【发布时间】:2019-10-07 09:01:11
【问题描述】:

我正在尝试从 tkinter 中的文件上传 gif 图像,但我收到一条错误消息。我是使用 tkinter 的新手,我知道要上传我们可以使用 PhotoImage 类的 gif 图像。

我下载了要上传的图片。

from tkinter import *      
root = Tk()      
canvas = Canvas(root, width = 300, height = 300)      
canvas.pack()      
img = PhotoImage(file="compman.gif")      
canvas.create_image(20,20, anchor=NW, image=img)      
mainloop()   

这是我得到的错误 无法打开“compman.gif”:没有这样的文件或目录

【问题讨论】:

  • 表示找不到文件。请描述您的文件/文件夹系统以及您如何运行脚本。

标签: python tkinter


【解决方案1】:

您应该会在此代码文件路径中找到此文件“compman.gif”。

this is your situation now

this is OK

【讨论】:

  • 不,不在代码文件路径中。如所写,它需要在当前工作目录中,这可能与代码所在的位置不同。
猜你喜欢
  • 2021-09-20
  • 2019-08-31
  • 2017-07-29
  • 2017-12-01
  • 1970-01-01
  • 2013-11-07
  • 1970-01-01
  • 1970-01-01
  • 2021-09-09
相关资源
最近更新 更多