0
def create_table(self, frame):
    data = [['Jeremy', 'Dean', '80%', 'Asteroids', 'Jupiter'], ['Matt', 'Damon', '75%', 'Asteroids', 'Jupiter']]  # sample data
    i = 0
    try:
        for row in data:
            j = 0
            for item in row:
                textVar = StringVar()
                textVar.set(item)
                # creates an entry for each piece of data
                entry = Entry(frame, state='readonly',textvariable=textVar, readonlybackground='lightgrey',width=14)
                entry.grid(row=i + 1, column=j)
                j += 1

            i += 1
    except TypeError:
        raise

I'm trying to create a table that will be displayed in the 'frame' frame, with the table consisting of the contents of the 2d array (so the first row would contain 'Jeremy, Dean ...', then 'Matt, Damon ...' in the second row)

Currently, whenever i run this program it outputs the entry boxes but without the text in them. It's weird because I've used this same code in another program and it worked fine but it doesn't work here.

I've tried using text=item instead of textvariable=textVar aswell but it doesn't seem to work for me either

amroman
  • 7
  • 2
  • What is Entry()? Please provide the code for this. – smurry Dec 04 '20 at 23:15
  • This snippet looks ok to me. Please provide a [mcve] that shows your problem. – Novel Dec 04 '20 at 23:24
  • `textVar` is a local variable. If you want to insert something in the `Entry` widget, are you aware that it has a method named `insert`? – Bryan Oakley Dec 04 '20 at 23:47
  • If you want to use `StringVar`s with your Entries, you have to keep a reference to all of them (append them to a global list, perhaps). Currently, the Vars are being garbage-collected almost immediately, causing a loss of their contents. – jasonharper Dec 05 '20 at 00:10
  • It works fine in my Windows 10 running Python 3.8.6. – acw1668 Dec 05 '20 at 11:19

0 Answers0