相关疑难解决方法(0)

按钮上的图像

我期望下面两个脚本的输出相同.

但是当我执行脚本1时,我没有在按钮上获得图像.但是,脚本2运行良好.

脚本1

from Tkinter import *
  class fe:
    def __init__(self,master):
      self.b=Button(master,justify = LEFT)
      photo=PhotoImage(file="mine32.gif")
      self.b.config(image=photo,width="10",height="10")
      self.b.pack(side=LEFT)
root = Tk()
front_end=fe(root)
root.mainloop()
Run Code Online (Sandbox Code Playgroud)

脚本2

from Tkinter import *
root=Tk()
b=Button(root,justify = LEFT)
photo=PhotoImage(file="mine32.gif")
b.config(image=photo,width="10",height="10")
b.pack(side=LEFT)
root.mainloop()
Run Code Online (Sandbox Code Playgroud)

python image tkinter button

19
推荐指数
1
解决办法
7万
查看次数

标签 统计

button ×1

image ×1

python ×1

tkinter ×1