0

I'm using tkintertable git cloned from github. Basically using the same example as the other SO question.

How do you add a raw of data into the table after the tkinter has been in its mainloop? How do you update data in the current table?

In the code below, I added a callback and use a tkinter after() to call. In the callback it tries to add a row to the data model. I also tried directly adding a key/value pair to the data object. Neither of them worked.

from Tkinter import *
from tkintertable.Tables import TableCanvas
from tkintertable.TableModels import TableModel
master=Tk()
tframe = Frame(master)
tframe.pack(fill='both')
data={'1': {'Klasa':'6A', 'E Hene': 1, 'E Marte': 2,'E Merkurre':3,'E Enjte':4,'E Premte':5},
      '2': {'Klasa':'', 'E Hene': 1, 'E Marte': 2,'E Merkurre':3,'E Enjte':4,'E Premte':5}}
model = TableModel()
table = TableCanvas(tframe,model=model)
table.createTableFrame()
model = table.model
model.importDict(data) #can import from a dictionary to populate model

def update_data(event=None):
    global data
    global model
    nk = "3"
    print "update_data \n"
    model.addRow(key=nk,
                 Klasa="333")
master.after(5000, update_data)

master.mainloop()
minghua
  • 5,981
  • 6
  • 45
  • 71

1 Answers1

1

From documentation

Update the table

This needs to be called to update the display after programmatically changing the table contents:

table.redraw()

So you need

model.addRow(key=nk, Klasa="333")
table.redraw()

And it works on my computer.

Community
  • 1
  • 1
furas
  • 134,197
  • 12
  • 106
  • 148