0

I'm using tkinter library to design UI. I'm trying to use my own images as buttons that run function. Everything else seems to be working but images are not displayed, just regular buttons. I'm kind of stuck now.

def load_buttons(self):
    files = []
    for i in range(5):
      files.append(f'{str(i)}.PNG')
    for i in range(len(files)):
      img = PhotoImage(file=files[i])
      self.buttons.append(Button(self.root,
                                 image=img,
                                 text=str(i),
                                 command=lambda c=i: print(self.buttons[c].cget("text"))))
      self.buttons[i].pack()
quamrana
  • 37,849
  • 12
  • 53
  • 71
  • Do the answers to this [question](https://stackoverflow.com/questions/16424091/why-does-tkinter-image-not-show-up-if-created-in-a-function) help at all? – quamrana Sep 14 '22 at 13:46

0 Answers0