1

I tried to create a button with an image, but the image gets very small and black.

I searched all over the internet for a solution, but it's still not working.

This is part of my code:

ph = tk.PhotoImage(file = "X.gif")
btn = tk.Button(master = back, command = game, height = 10, width = 20)
btn.config(image = ph)
btn.image = ph
btn.grid(row = 0, column = 0)
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
Daniel
  • 229
  • 1
  • 8

1 Answers1

0

I managed to do it by removing the height and width parameters in the Button constructor, and resizing the image.

Now the code is:

ph = tk.PhotoImage(file = "X.gif")
btn = tk.Button(master = back, command = game)
btn.config(image = ph)
btn.image = ph
btn.grid(row = 0, column = 0)

I understood that after defining the image, the width and the height are the size in pixels.

Daniel
  • 229
  • 1
  • 8