# Adapted from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82965 import Tkinter import tVector # tVector.py class TestDisplay: def __init__(self, parent, debug=0,): self.m_debug = debug self.m_parent = parent initialList = [ ("Row1Col1", "Row1Col2", ), ("Row2Col1", "Row2Col2", ), ] self.m_needsRebuild = True self.m_layout = None self.m_dataGrid = list() for i in initialList: if self.m_debug > 0: print "Adding row:", i self.m_dataGrid.append(i) # # Build the interface: def rebuildInterface(self, ): if not self.m_needsRebuild: return col1List = list() col2List = list() # Here is where we would do the magic with pack: # self.m_parent.forget() for first,second in self.m_dataGrid: col1List.append( tVector.tW( Tkinter.Label, first, text=first, anchor=Tkinter.E, ) ) col2List.append( tVector.tW( Tkinter.Label, first, text=second, anchor=Tkinter.E, ) ) self.m_layout = tVector.tCol( tVector.tRow( tVector.tW(Tkinter.Button, 'but2', text="Add row", command=self.addRow, ), tVector.tW(Tkinter.Entry, 'col1', text="col1", ), tVector.tW(Tkinter.Entry, 'col2', text="col2", ), ), tVector.tRow( tVector.tCol( *col1List ), tVector.tCol( *col2List ), ), ) self.m_layout.tBuild(self.m_parent) self.m_needsRebuild = False # def addRow(self): if self.m_debug > 0: print "clicked button2 to add row" col1 = self.m_layout.wids["col1"] col2 = self.m_layout.wids["col2"] newRow = (col1.get(),col2.get(),) if self.m_debug > 0: print "addRow: ", newRow self.m_dataGrid.append(newRow) self.m_needsRebuild = True self.rebuildInterface() # def mainloop(self): self.rebuildInterface() self.m_layout.mainloop() if __name__ == '__main__': root = Tkinter.Tk() root.title("Test dynamic") app = TestDisplay(root, debug=10) app.mainloop()