from tkinter import *
class Application(Frame):
def init(self, master=None):
super().init(master)
self.master = master
self.pack()
self.create_widgets()
def create_widgets(self):
self.w1 = Text(root, width=60, height=30, bg="gray")
self.w1.pack()
self.w1.insert(1.0, "0123456789\n")
Button(self, text="插入",).pack(side="left")
Button(self, text="插入2",).pack(side="left")
Button(self, text="插入图片", command=self.add_image).pack(side="left")
def add_image(self):
photo = PhotoImage(file="D:/测试用图/a0.gif")
self.w1.image_create(END, image=photo)
root = Tk()
root.geometry("600x500+400+200")
app = Application(master=root)
root.mainloop()
代码运行没问题,图片好像也插入进去了,就是显示不出来是为什么呢