2 回答
![?](http://img1.sycdn.imooc.com/54584eff000195a302200220-100-100.jpg)
TA贡献1802条经验 获得超4个赞
情况1:
问题可能是因为您的 tkinter 版本不支持 png。下面是如何继续使用PIL/ Pillow。
首先安装它,在你的终端中这样说。
pip install Pillow
然后...
from PIL import Image, ImageTk #import it
....
back_btn_img = ImageTk.PhotoImage(Image.open('images/back.png')) #instantiate the image
您也可以为其余图像文件复制相同的格式。
这样做的一个优点是,您还可以调整图像大小。
案例2:
该错误也可能是因为文件格式不正确,您确定转换正确还是文件已损坏?您可能想检查所有这些,并执行正确的转换方法(如果仅通过更改扩展名进行转换)。hello.jpg请记住,如果要将文件转换为 png,您应该使用软件或在线网站来执行此操作,但不要将文件重命名为hello.png.
希望这有帮助,如果有任何错误或疑问,请告诉我。
![?](http://img1.sycdn.imooc.com/545862db00017f3402200220-100-100.jpg)
TA贡献1784条经验 获得超2个赞
使用 PIL :
from tkinter import *
from PIL import ImageTk, Image
root = Tk()
root.title("Creeper Awww Man MP3 Player")
root.geometry("500x400")
# Create Playlist Box
playlist_box = Listbox(
root,
bg = "black",
fg = "#4666FF",
width = 60
)
playlist_box.pack(pady=20)
back_btn_img = ImageTk.PhotoImage(Image.open('back.png').resize((50, 50), Image.ANTIALIAS))
# .resize(xx, xx) ,, changing image size
# Create Button Frame
control_frame = Frame(root)
control_frame.pack(pady=20)
# Create Play/Stop etc Buttons
back_button = Button(control_frame, image=back_btn_img,)
back_button.grid(row=0, column=0, padx=10)
root.mainloop()
添加回答
举报