Python Forum
[Tkinter] the picture disappears
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] the picture disappears
#1
Hello!
Tell me, please ... I move the picture in the class using a separate method, and when the picture receives the last coordinate, then it disappears, and I need the picture to not disappear.

...
root = tk.Tk()
root.geometry('1200x900+2+10')
root.resizable(width = False, height = False)

puth = 'C:\\school\\general\\'            #основной путь к игре


canvas1 = Canvas(root, width = 1200, height = 900, bg = "#536878", highlightthickness = 0)
canvas1.place(x = 0, y = 0)

im    = Image.open(puth + 'image\\biblio.PNG').convert('RGBA')
im_01 = ImageTk.PhotoImage(im)
fon   = canvas1.create_image(0, 0, anchor = NW, image = im_01)
canvas1.update()

    
def image_load():
   
    robots = []
    path = 'C:\\school\\general\\image\\'
    for i, filename in enumerate(os.listdir(path)):
        if filename.find("robot") == False:
            if (filename.endswith(".png") or filename.endswith(".PNG")):
                path1 = path + '\\' + filename
                im = Image.open(path1).convert('RGBA')
                datas = im.getdata()
                opacity_level = 0
                newData = []
                for item in datas:
                    if item[0] == 127 and item[1] == 127 and item[2] == 127:
                        newData.append((0, 0, 0, opacity_level))
                    else:
                        newData.append(item)
                im.putdata(newData)
                robots.append(ImageTk.PhotoImage(im))
                    
    starts = Robot(robots)

class Robot:
    
    def __init__(self, robots):
        
        self.robots = robots
        self.ind = 1
        self.y1  = 15
        self.rbs = canvas1.create_image(600, 300, anchor = 'nw', image = robots[1])
        self.move_rob(self.ind, self.rbs, self.robots, self.y1)
    
    
    def move_rob(self, ind, rbs, robots, y1):

        self.cadr = self.robots[int(self.ind)]
        
        if int(self.ind) == 16:
            self.ind = 0
        if int(self.y1) > 0:
            self.y1 -= 0.75
        else:
            self.y1 -= 0.1
        
        canvas1.itemconfig(self.rbs, image = self.cadr)
        canvas1.move(self.rbs, 0, self.y1)
        
        if self.ind != 0:
            self.ind += 0.2
            root.after(30, self.move_rob, self.ind, self.rbs, self.robots, self.y1)
        else:
            self.robot(self.robots)
    
    
    def robot(self, robots):
        
        self.robot_x = canvas1.coords(self.rbs)[0]
        self.robot_y = canvas1.coords(self.rbs)[1]
        self.rbs = canvas1.create_image(self.robot_x, self.robot_y, image = self.robots[16])
        print('Robot')


image_load()
root.mainloop()
Reply
#2
I solved the problem))) Creating a list of pictures transferred from the function (line 20) to the main code (on line 17) and it worked.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Thumbnail picture won't show, and no error. why? Ragnar_Itachi 1 1,524 Mar-20-2023, 03:15 PM
Last Post: deanhystad
  a neat picture based on recursive number phillip1882 1 2,767 Sep-06-2018, 02:48 AM
Last Post: scidam
  tkinter picture importation problema SheeppOSU 1 2,948 May-16-2018, 09:26 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

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