0

So, I have tried displaying the same image, it should be able to display 10 of the same picture and I was also wondering where could use the pady and padx to space the pictures out.

Here is what I have tried so far:

        for img in range(10):
            canvas = Canvas(self.frame, width=30, height=30)
            canvas.pack()
            img = ImageTk.PhotoImage(Image.open("DicePic.jpeg"))
            canvas.create_image(50, 50, anchor=NW, image=img)
            self.frame.mainloop()
Blue
  • 19
  • 4
  • Does this answer your question? [Why does Tkinter image not show up if created in a function?](https://stackoverflow.com/questions/16424091/why-does-tkinter-image-not-show-up-if-created-in-a-function) – Matiiss Apr 26 '21 at 14:27
  • You never use `self.dicePic` in any image container, like `Label` or `Canvas`, so no image will be shown. Another issue is that you use same instance variable `self.dicePic` for the ten instances of `PhotoImage()`. – acw1668 Apr 26 '21 at 14:35
  • Ok, I tried fixing my code but it still won't display the picture – Blue Apr 26 '21 at 14:51
  • You shouldn't be calling `mainloop` inside a loop. `mainloop` itself is a loop, as the name implies. – Bryan Oakley Apr 26 '21 at 14:56
  • Also the size of the canvas is 30x30 pixels, but you put the image at `(50, 50)` which is outside of the viewable area of the canvas. You should only create one canvas for all the images at different locations instead of one canvas per image. – acw1668 Apr 26 '21 at 15:11
  • Also move the `img = ...` outside of the loop. That way you will only have 1 `ImageTk` object to worry about. – TheLizzard Apr 26 '21 at 16:03

0 Answers0