没有这样的文件或目录python图像

时间:2018-03-14 18:41:19

标签: python python-2.7 tkinter

我正在尝试将图像放在tkinter按钮上,但它看起来不起作用。

root.geometry('512x512')
vbuckimage = tkinter.PhotoImage(file='vbuckicon.gif')
#vbucks button
vbucksButton = tkinter.Button(root,image=vbuckimage,height=5,width=10)

vbucksButton.place(x=256,y=256)
root.mainloop()

图像与.py文件位于同一位置

1 个答案:

答案 0 :(得分:0)

您似乎遇到与here相同的问题 试试这个解决方案:

import os
from tkinter import *
base_folder = os.path.dirname(__file__)
image_path = os.path.join(base_folder, 'vbuckicon.gif')
vbuckimage = PhotoImage(file=image_path)