我不明白为什么我的代码不能工作。
from tkinter import *
"""
We need the Pillow library (or PIL) to import images in out application)
I need to import both ImageTk and Image
"""
from PIL import ImageTk, Image
"""
doens't work at the moment bc I can't figure out what's wrong with PIL
"""
root = Tk()
root.title("Icono, Boton Exit y Imagenes")
root.geometry("200x100")
'''
root.iconbitmap("c:/gui/codemy.ico")
this is to put a personalized icon to the window application
'''
my_img = imageTk.PhotoImage(Image.open("something.png"))
my_label = Label(image=my_img)
my_label.pack()
button_quit = Button(root, text="Salir del programa", command=root.destroy)
button_quit.pack()
"""
https://www.geeksforgeeks.org/how-to-close-a-tkinter-window-with-a-button/
for other examples of exit button
also command=root.quit
"""
root.mainloop()
我试着四处查找,根据别人的要求,我没有安装两个Python版本;
我安装了枕头;
PIL我无法安装,因为pip找不到它。
我不知道下一步该做什么。
谢谢你阅读我的问题。
编辑:这是回溯。
跟踪(最近一次调用):
文件"F:\python ejercicios\TkIconsImagesExitButtons.py",第6行,>in
从PIL导入ImageTk,图像
ModuleNotFoundError:没有名为“PIL”的模块
Edit2:这些是我觉得有点困惑的警告吗?
第6行:已经定义的名称“图像”(可能是通过导入)
第6行:从PIL导入的未使用的ImageTk看起来不使用导入的模块或变量。
第22行:未定义名称"imageTk“
第22行:"TypeImage“没有属性”打开“
最终编辑:发现问题。感谢那些试图帮助我的人。
发布于 2022-10-22 07:50:06
嘿,你可以试试下面的-
my_img = ImageTk.PhotoImage(Image.open("something.png"))
使用命令提示符或powershell pip install --upgrade pip
中的命令
发布于 2022-10-25 01:58:27
所以我的实际问题是我安装了不止一个Python.exe,Thonny (我使用的IDE )实际上没有枕头包,所以当我运行这个应用程序时,它失败了。非常感谢你的帮助。
https://stackoverflow.com/questions/74164827
复制相似问题