求大神!!python tkinterGUI插入图片,图片目录放在哪里,运行结果显示找不到图片
def callback():
var.set("吹吧你,我才不信来!")
root = Tk()
frame1 = Frame(root)
frame2 = Frame(root)
var = StringVar()
var.set("您所下载的影片含有未成年人限制内容,\n请满18周岁再点击观看")
textLabel = Label(frame1,
textvariable=var,
justify=LEFT)
textLabel.pack(side=LEFT)
photo = PhotoImage(file='2.gif')
imgLabel = Label(root, image=photo)
imgLabel.pack(side=RIGHT)
theButton = Button(frame2, text="我已满18周岁", command=callback)
theButton.pack()
frame1.pack(padx=10, pdy=10)
frame1.pack()
root.mainloop()
运行出错:C:\Users\DELL\PycharmProjects\EX1\venv\Scripts\python.exe C:/Users/DELL/PycharmProjects/EX1/test1.PY
Traceback (most recent call last):
File "C:/Users/DELL/PycharmProjects/EX1/test1.PY", line 17, in <module>
photo = PhotoImage(file='2.gif')
File "C:\Users\DELL\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 3542, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Users\DELL\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 3498, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't open "2.gif": no such file or directory
求大神解惑
{:10_266:}一直找不到解决方案,求大神啊!先谢谢! 你的图片在什么目录里啊? alltolove 发表于 2018-10-6 08:56
你的图片在什么目录里啊?
我不知道应该放哪,就放了桌面上去了{:10_266:}
应该放在哪里,求解答 这个应该是和你python文件同目录下面吧。如果你的图片放在桌面,你这个python也应该放桌面呀。
页:
[1]