I need to create a table with a huge amount of rows ( more than 2000 ). Each row should be able to hold widgets. But when I try to add entries after about 1714th the grid stops to grow and all the following widgets are drawn atop each other. The issue seems to be related to the height of the grid because if I change the border width of an entry the that value will also change.
import Tkinter as tk
class Example( tk.Frame ):
def __init__( self, root ):
tk.Frame.__init__( self, root )
self.canvas = tk.Canvas( root, background = "#ffffff", borderwidth = 0 )
self.frame = tk.Frame( self.canvas, background = "#ffffff" )
self.vsb = tk.Scrollbar( root, orient = "vertical",
command = self.canvas.yview )
self.canvas.configure( yscrollcommand = self.vsb.set )
self.vsb.pack( side = "right", fill = "y" )
self.canvas.pack( side = "left", fill = "both", expand = True )
self.canvas.create_window( ( 4, 4 ), window = self.frame, anchor = "nw",
tags = "self.frame" )
self.frame.bind( "<Configure>", self.on_frame_configure )
self.populate()
def update( self ):
self.frame.update()
def add( self ):
for id in xrange( 2000 ):
entry_id = tk.Entry( self.frame, width = 10, justify = 'center',
borderwidth = "1",
relief = "solid",
bg = '#C8D4FA' )
entry_id.grid( row = 1 + id, column = 0 )
entry_id.insert( 1, 1 + id )
def populate( self ):
self.frame.grid_rowconfigure( 0, weight = 1 )
button = tk.Button( self.frame, text = 'Click', command = self.add ).grid( row = 0, column = 0 )
def on_frame_configure( self, event ):
'''Reset the scroll region to encompass the inner frame'''
self.canvas.configure( scrollregion = self.frame.bbox( 'all' ) )
#self.canvas.configure( scrollregion = self.canvas.grid )
def main():
root = tk.Tk()
example = Example( root )
root.mainloop()
if __name__ == '__main__':
main()