【问题标题】:Debian, issue with ImageTk: "cannot import 'ImageTk' from 'PIL' "Debian,ImageTk 问题:“无法从 'PIL' 导入 'ImageTk'”
【发布时间】:2020-03-28 15:52:35
【问题描述】:

我的进口:

import tkinter as tk
from PIL import ImageTk, Image
import os 

我的代码:

image = Image.open("path/download.bmp")
root = tk.Tk()
photo = ImageTk.PhotoImage(image)

我尝试了所有找到的 apt-get 安装命令,但没有任何效果。请帮忙。

当我运行像sudo apt-get install python3-pil.imagetk 这样的命令时,我得到了

Package python3-pil.imagetk is not available, but is referred to by another package.

 ... Package 'python3-pil.imagetk' has no installation candidate

【问题讨论】:

  • 你有没有把你的脚本命名为PIL.py?这将被import 接收,而不是实际的模块。
  • @jasonharper,不,我将其命名为“gettingStarted.py”。
  • @alais1 试试pip3 install Pillow

标签: python tkinter python-imaging-library


【解决方案1】:

所以...我没有找到解决方案,但我最终只是摆脱了 ImageTk 类,写了一些简单的东西

photo = PhotoImage(file="path/download.gif")

此解决方案还需要我将 .bmp 转换为 .gif 。

【讨论】:

    猜你喜欢
    • 2019-08-13
    • 1970-01-01
    • 1970-01-01
    • 2017-12-03
    • 1970-01-01
    • 2020-07-26
    • 1970-01-01
    • 2012-06-19
    • 2021-10-01
    相关资源
    最近更新 更多