2

For some reason the image I am trying to have on this button will not show up, although I think the Image does exist when the code runs since the button resizes but does not show the image. I have thought this was due to the image properties but have tried many other images that do not work! Have I missed something quite obvious and am being stupid? PS the button will not call its function when the 'goast image' is there.

settingimage = PhotoImage(file="icons8-settings-50 (1).png")

settingsbut = Button(window, command=settings, image=settingimage)
settingsbut.place(x=10, y=10)

I Have tried resizing the button many times, tried using "compound", using different images and I have tried using a label as a dummy for the image to sit on while the button does not. None of these have resulted in the image being shown on the button. Although no errors occur and the button resizes for the image leading me to think its visual.

codester_09
  • 5,622
  • 2
  • 5
  • 27

2 Answers2

0

If it is inside a function then just do this.


def functionName():
    global settingimage
    ...
    settingimage = PhotoImage(file="icons8-settings-50 (1).png")
    settingsbut = Button(window, command=settings, image=settingimage)
    settingsbut.place(x=10, y=10)
    ...

The problem is that the Python's garbage collector collects the settingimage because of no other usage of settingimage. But adding global can remove that.

For more information you can see this post or you can see this Stack Overflow Post

codester_09
  • 5,622
  • 2
  • 5
  • 27
0

I have 2 concerns:

  1. why is settingsbut lines indented?
  2. is your image, i.e. icons8-settings-50 (1).png in the same file as your Python script?

if these are not the cause of the problem, I suggest that you share a larger section of your code along with an SS of your output/error.

DhruvFlare
  • 31
  • 4