Python Forum
Display image in tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Display image in tkinter
#8
Ok so this seems working, but now I want to implement this image displaying feature into my for cycle. It should look like this:

for i in range(self.height // self.field_size):
            for j in range(self.width // self.field_size):
                self.field_icon = tkinter.PhotoImage(file="GroundGravel_Grass.png")
                if self.layout[field] == "0":
                    self.canvas.create_image(j*50, i*50, anchor=NW, image=self.field_icon)
                elif self.layout[field] == "1":
                    self.canvas.create_rectangle(j*50, i*50, j*50+self.field_size, i*50+self.field_size, fill="blue", outline="yellow")
                elif self.layout[field] == "2":
                    self.canvas.create_rectangle(j*50, i*50, j*50+self.field_size, i*50+self.field_size, fill=self.sand, outline="yellow")
Basically, this program reads a file with number 0, 1 and 2 and according to specific numbers it should put an image to the correct position (according to "i" and "j") and so create a square grid (should work as a playfield later). You can see that in case of numbers 1 and 2 I have just colors yet, I stopped there, because even number 0 didn´t work with a picture of a grass. It draws just a last square, image here:

[Image: screen.png]

The whole black area should be covered with such a green grass tiles, but when I replace image of a grass by basic green color tile, it works. Can you help me?
Reply


Messages In This Thread
Display image in tkinter - by dan789 - Nov-28-2018, 06:15 PM
RE: Display image in tkinter - by Larz60+ - Nov-28-2018, 07:06 PM
RE: Display image in tkinter - by woooee - Nov-28-2018, 07:13 PM
RE: Display image in tkinter - by jfong - Nov-30-2018, 07:36 AM
RE: Display image in tkinter - by dan789 - Dec-01-2018, 05:29 PM
RE: Display image in tkinter - by Gribouillis - Dec-01-2018, 06:17 PM
RE: Display image in tkinter - by jfong - Dec-02-2018, 01:33 AM
RE: Display image in tkinter - by dan789 - Dec-09-2018, 06:46 PM
RE: Display image in tkinter - by Gribouillis - Dec-09-2018, 07:42 PM
RE: Display image in tkinter - by dan789 - Dec-09-2018, 08:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter: An image and label are not appearing. emont 7 857 Mar-21-2024, 03:00 PM
Last Post: deanhystad
  My Background Image Is Not Appearing (Python Tkinter) HailyMary 2 4,584 Mar-14-2023, 06:13 PM
Last Post: deanhystad
  simple tkinter question function call not opening image gr3yali3n 5 3,570 Aug-02-2022, 09:13 PM
Last Post: woooee
  [Tkinter] Tkinter don't change the image DQT 2 1,692 Jul-22-2022, 10:26 AM
Last Post: menator01
  [PyQt] Cannot Display Image after Selecting Image bintangkecil 4 2,645 Jun-12-2022, 08:18 AM
Last Post: Axel_Erfurt
  looking for scripts that do simple image display Skaperen 10 4,349 Sep-13-2021, 05:35 PM
Last Post: FullOfHelp
  How to redraw an existing image to a different image TkInter zazas321 6 6,030 Jul-08-2021, 07:44 PM
Last Post: deanhystad
  tkinter showing image in button rwahdan 3 5,727 Jun-16-2021, 06:08 AM
Last Post: Yoriz
  tkinter button image Nick_tkinter 4 4,146 Mar-04-2021, 11:33 PM
Last Post: deanhystad
  how to resize image in canvas tkinter samuelmv30 2 17,968 Feb-06-2021, 03:35 PM
Last Post: joe_momma

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020