0

I am having issue with this code. Actually, 1. Download the images using url 2. Save those images to in a server 3. Display them in a canvas

The problem I am having is it's showing only the last image (in this case img2 from url2) from the list, not the first one, Even though I do see a blank space has been added in the Canvas for the first image.

Any one know what I am missing here. I appreciate your help.

Are there any other ways to get the images and showing in canvas, without saving them in to the local.


class open_child_window:
    def init(self, master):
        self.master = master
        master.title("Img")

    url1 ="http:img1"
    url2 ="http:img2"


    vscrollbar = Tk.Scrollbar(self.master,orient=VERTICAL)
    hscrollbar=Tk.Scrollbar(self.master,orient=HORIZONTAL)

    self.canvas= Tk.Canvas(self.master,background = "White",yscrollcommand=vscrollbar.set,xscrollcommand=hscrollbar.set)
    self.frame = Tk.Frame(self.canvas)
    vscrollbar.config(command=self.canvas.yview)
    vscrollbar.pack(side=Tk.RIGHT, fill=Tk.Y)

    hscrollbar.pack(side=Tk.BOTTOM,fill=Tk.X)
    hscrollbar.config(command=self.canvas.xview)

    self.canvas.create_window(0,0,window=self.frame, anchor='nw')            

    self.list_images = []


    contents = urllib.request.urlopen(ur1l)

    plt.imshow(plt.imread(contents))
    file_name = "./img1.png"
    plt.savefig(file_name, format='png', dpi=180)

    gif1 = PhotoImage(file = file_name)
    self.canvas.image_names = gif1
    self.canvas.create_image(50, 10, image = gif1, anchor = NW)


    contents = urllib.request.urlopen(url2)

    plt.imshow(plt.imread(contents))
    file_name = "./img2.png"
    plt.savefig(file_name, format='png', dpi=180)

    gif2 = PhotoImage(file = file_name)
    self.canvas.image_names = gif2
    self.canvas.create_image(600, 700, image = gif2, anchor = NW)


    self.master.update()  
    self.canvas.config(scrollregion=self.canvas.bbox("all"))
    self.canvas.pack(side="top",fill='both',expand=True)
    self.frame.pack()
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
vas
  • 53
  • 2
  • 8

1 Answers1

0

I was able to resolve with my issue.

in case if some one else looking for the solution.

Have added self in front of gif1 and gif2 like self.gif1 and self.gif2.

vas
  • 53
  • 2
  • 8