|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
为啥这段代码的图片会倒不进去呢?
from tkinter import *
root=Tk()
textLabel =Label(root,text='我爱你不后悔,也尊重故事结尾',fg='red')
textLabel.pack(side=LEFT)
photo= PhotoImage(file="22.gif")
imgLabel= Label(root,image= photo)
imgLabel.pack(side=RIGHT)
mainloop()
错误提醒
Traceback (most recent call last):
File "G:/开发游戏/爱情啊.py", line 9, in <module>
photo= PhotoImage(file="22.gif")
File "G:\Python\lib\tkinter\__init__.py", line 3545, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "G:\Python\lib\tkinter\__init__.py", line 3501, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't open "22.gif": no such file or directory
>>>
将图片拷贝到 C 盘根目录,然后把代码改成:
- from tkinter import *
- root=Tk()
- textLabel =Label(root,text='我爱你不后悔,也尊重故事结尾',fg='red')
- textLabel.pack(side=LEFT)
- photo= PhotoImage(file="C:/22.gif")
- imgLabel= Label(root,image= photo)
- imgLabel.pack(side=RIGHT)
- mainloop()
复制代码
|
|