Tkinter displaying 300 records sluggish
Irene Barg
ibarg at as.arizona.edu
Sun Mar 9 17:15:54 EST 2003
Hello All,
I have a Tkinter/PMW GUI interface to a flatfile (in memory) database
(FlatDB, written by Colin Svingen). When displaying 300 records, it takes approx
10 seconds on a Sun Ultra 60 2x360MHz, with 1024MBytes RAM running under
Python 2.1, and scrolling through the results is slugish. On a Toshiba Satellite
Pro, Pentium 4, 1.70GHz CPU, 260MB RAM, running RedHat Linux (v8.0)and Pytho2.2,
it takes approx. 5 seconds to display 300 records, but scrolling is much faster.
The result set is a list of lists. The actual size of the db is only 97K, which
shouldn't be a problem with either machine. Are there any coding techniques to
improve performance with Tkinter? Has this been documented anywhere?
The portion of code that handles the looping through the results follows.
I appreciate your comments. --irene barg
def displayColumns(self,style):
"""Tabular view of data."""
#print "displayColumns: action=%s style=%s" % (self.action,style)
#print " skipfields=",self.skipfields," skipcols=",self.skipcols
offset = 0
tkclass = None
# if action is 'Delete' or 'Modify', then first column is a
# 'Select' Checkbutton, or Button (respectively).
if (self.action == 'Delete') or (self.action == 'Modify'):
l = Tkinter.Label(self.sframe,text='%s' % self.action,
borderwidth=1,
background='lightgrey',
foreground='black',
relief='raised')
l.grid(row=0,column=0,sticky='NSEW')
self.sframe.columnconfigure(0,weight=0)
offset=1
if (self.action == 'Delete'): tkclass='Tkinter.Checkbutton'
if (self.action == 'Modify'): tkclass='Tkinter.Button'
# put our column names across the top
numcol = len(self.columns)
for j in range(numcol):
if (style == 'Compact') and (j in self.skipcols): continue
l = Tkinter.Label(self.sframe,text=string.capitalize(self.columns[j]),
borderwidth=1,
background='lightgrey',
foreground='black',
relief='raised')
l.grid(row=0,column=j+offset,sticky='NEW',padx=2,pady=2)
self.sframe.columnconfigure(j+offset,weight=0)
self.sframe.rowconfigure(0,weight=0)
# our data rows follow
rn = 1
delvars = []
maxw = 30
h = 1
for i in range(self.numrecs):
if style == 'Normal':
h = self.lineheight(maxw,self.data[i])
if h <= 0: h = 1
for j in range(numcol):
if (style == 'Compact') and (j in self.skipcols): continue
if self.data is None:
val = ""
w = 10
else:
val = self.data[i][j]
w = len(val)
if w > maxw: w = maxw
if (style == 'Normal') and (self.urlndx != j):
#wrap long text fields, except URL
field = Tkinter.Text(self.sframe,
height=h,
width=w,
wrap='word',
background='white',
foreground='black')
field.insert('1.0',val)
else:
##Compact
field = Tkinter.Entry(self.sframe,
width=w,
background='white',
foreground='black')
field.insert(0,val)
field.configure(state='disabled')
if (self.action == 'Search') and (self.urlndx == j):
field.configure(foreground='blue',
highlightbackground='lightgrey',
relief='raised',)
field.bind('<Double-Button-1>',self.viewPublication)
field.grid(row=rn,column=j+offset,sticky='NEW',padx=2,pady=2)
self.sframe.columnconfigure(j+offset,weight=0)
# insert Select column if action Delete/Modify
if ((self.action == 'Modify') or (self.action == 'Delete')):
b = Tkinter.Radiobutton(self.sframe,
text='%d' % i,
command=self.selectRecord,
variable=self.pickvar,
value=i,
borderwidth=1,
background='white',
foreground='black',
relief='raised',)
b.grid(row=rn,column=0,sticky='NEW',padx=2,pady=2)
self.sframe.columnconfigure(0,weight=0)
self.sframe.rowconfigure(rn,weight=0)
rn = rn +1
More information about the Python-list
mailing list