没有这样的文件或目录python imag

2024-10-03 23:22:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我想把一个图像放在一个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文件位于同一位置


Tags: 图像imagetkinterbuttonrootgif按钮file
1条回答
网友
1楼 · 发布于 2024-10-03 23:22:03

你似乎和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)

相关问题 更多 >