把图片赋值给一个变量 然后调用就说找不到
import tkinter
import os
LOGO = '茄子.ico'
IMGE_XPATH='134.png'
class Mainform:
def init(self):
oot = tkinter.Tk()
oot.title('1')
oot.iconbitmap(LOGO)
oot.geometry('200x200')
oot.maxsize(300,200)
text = tkinter.Text(oot,width=40,height=10,font=('微软雅黑',10))
text.image_create('end',image=IMGE_XPATH)
text.pack()
oot.mainloop()
def main():
Mainform() #实例化窗体 调用class里的INIT函数进行窗体显示
if name == "main": # 在其他的程序里后面的代码将不被执行 或被导入名字为当前文件的名字
# print(os.getcwd())
# print(IMGE_XPATH)
# print("check",os.path.exists(IMGE_XPATH))
main()#调用主函数 然后主函数调用class里的函数实现窗口的显示
return self.tk.call(
kinter.TclError: image "134.png" doesn't exist
进程已结束,退出代码为 1
把路径打印出来没问题 文件路径是对的但是就是找不到,PNG GIF都试过
把图片显示出来
self.text = tkinter.Text(oot,width=40,height=10,font=('微软雅黑',10))
self.text.image_create('end',image=IMGE_XPATH)
self.text.pack()
都加上self试试或者
photo = tk.PhotoImage(file="18.png")#file:t图片路径
imgLabel = tk.Label(frame1,image=photo)#把图片整合到标签类中
imgLabel.pack(side=tk.RIGHT)#自动对齐