|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
12,png的这个文件是有的 改成GIF也不行
import tkinter as tk
window = tk.Tk()
window.title('my window')
window.geometry('200x200')
canvas = tk.Canvas(window,bg = 'blue',height = 100,width = 200,)
image_file = tk.PhotoImage(file = './12.png')
image = canvas.create_image(0,0,anchor = 'nw',image = image_file)
canvas.pack()
b = tk.Button(window,text = 'move',command = moveit).pack()
windw.mainloop()
C:\Users\10420\AppData\Local\Programs\Python\Python38-32\python.exe E:/demo/shixun1/demo31.py
Traceback (most recent call last):
File "E:/demo/shixun1/demo31.py", line 12, in <module>
image_file = tk.PhotoImage(file = './12.png')
File "C:\Users\10420\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 4061, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Users\10420\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 4006, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't open "./12.png": no such file or directory
Process finished with exit code 1
本帖最后由 YunGuo 于 2021-1-21 22:08 编辑
然而事实是,你函数不定义直接运行会报错没有这个函数,并不会弹出任何窗口(实测)。
你这个代码,那两处修改后,我运行是没有问题的,另外提示找不到图片,你图片是不是与在python文件在同一层,图片名字是不是不正确,是不是名字中有空格?这都是需要注意的。
|
-
|