0

I have for loop creating a bunch of frames that contains data including an image. All the data is stored in a numpy array. It outputs all the data fine, however no image is displayed, with no error. However, if I just display a single image from outside the for loop its fine, but this will not work for me.

This is it when I display an image from enter image description hereoutside the for loop

And this is when I try to access the data from the array in the for loopenter image description here

This is my code:

    def invest_rows(self, parent):
        # logo, name, information, percentage, price
        self.stock_data = np.array([['goldman.png', 'Goldman Sachs Group, Inc', 'GS | NYSE | Banking & Finance,', '+0.30%', '$364.80'],
                                   ['nvidia.png', 'NVIDIA Corp', 'NVDA | NASDAQ | Technology', '-3.20%', '$784.28'],
                                   ['amd.png','Advance Micro Devices Inc.', 'NVDA | NASDAQ | Technology', '+1.20%', '$88.56'],
                                   ['tesla.png', 'Tesla Inc', 'TSLA | NASDAQ | Transport', '-2.55%', '$682.14']])



        root.columnconfigure(1,weight=1)
        self.invest_frame = Frame(root)
        self.invest_frame.grid(row=0,column=1,rowspan=2,sticky=N+S+E+W)
        #self.invest_frame.config(background='pink')


        self.image = Image.open('goldman.png')
        self.image1 = self.image.resize((100, 100))
        self.fuck = ImageTk.PhotoImage(self.image1)

        self.graph = Image.open('up_graph.png')
        self.image2 = self.graph.resize((100,100))
        self.fuck2 = ImageTk.PhotoImage(self.image2)

        for x in range(4):
            #print(self.stock_data[0, x])

            invest_row = Frame(self.invest_frame)
            self.invest_frame.columnconfigure(0, weight=2)
            invest_row.grid(row=x,column=0,padx=5,pady=5,sticky=E+W)

            image = Image.open(self.stock_data[x,0])
            print(self.stock_data[x,0])
            image1 = image.resize((100, 100))
            logo_img = ImageTk.PhotoImage(image1)

            invest_row.config(background='grey80')

            logo = Label(invest_row,image=self.logo_img,bg='grey80')
            logo.grid(row=0,column=0,rowspan=3)

            name = Label(invest_row, text=self.stock_data[x,1], font="GoldmanSans 18 bold",fg='grey',bg='grey80')
            name.grid(row=0,column=1,sticky=N+W,columnspan=2)

            details = Label(invest_row,text=self.stock_data[x,2], font='GoldmanSans 14 bold',bg='grey80')
            details.grid(row=1,column=1,sticky=N,columnspan=2)
  • 1
    [Why do my Tkinter images not appear?](https://web.archive.org/web/20201111190625id_/http://effbot.org/pyfaq/why-do-my-tkinter-images-not-appear.htm) – 8349697 Jul 17 '21 at 17:28
  • If you are still looking for an answer then try inserting a `root.update()` inside the loop. – Derek Jul 17 '21 at 23:53

0 Answers0