如何在Tkinter中添加图像?这给了我一个语法错误:root = tk.Tk()img = ImageTk.PhotoImage(Image.open(path))panel = tk.Label(root, image = img)panel.pack(side = "bottom", fill = "both", expand = "yes")root.mainloop()
3 回答

四季花海
TA贡献1811条经验 获得超5个赞
上面的代码中没有“语法错误”-它发生在其他行中(上面不是您的所有代码,因为没有导入,也没有path变量的声明),或者您遇到了其他错误类型。
上面的示例对我来说很好,在交互式解释器上进行了测试。

Smart猫小萌
TA贡献1911条经验 获得超7个赞
Win32 14.2013年5月的Python 3.3.1 [MSC v.1600 32位(Intel)]
通过遵循上面的代码,这对我有用
from tkinter import *
from PIL import ImageTk, Image
import os
root = Tk()
img = ImageTk.PhotoImage(Image.open("True1.gif"))
panel = Label(root, image = img)
panel.pack(side = "bottom", fill = "both", expand = "yes")
root.mainloop()
没有找到匹配的内容?试试慕课网站内搜索吧
添加回答
举报
0/150
提交
取消