PMW ScrolledFrame

Irene Barg ibarg at as.arizona.edu
Wed Mar 19 18:34:05 EST 2003


Hello All,

I have Tkinter/PMW interface to a small flat-file database.  I give 
the user the option to display the results to a search in either 
Column or Row format.  Column format is tabular data, the Row format 
is card or record format.  If the user does a wildcard search, the 
program will display all records in the db, display time takes about 
10-11 seconds for approx 318 records.  To make it feel more 'robust', 
I introduced a Display Option, which allowed the user to set the 
'Rows Per Page' to display. RowsPerPage defaults to 10, but setting 
it to 30 or 100 makes it feel more robust.  I added buttons for 
nextpage, prevpage, start, end.

The problem is this.  My top window is a PMW ScrolledFrame.  If I
display the 'pages' of data in Column (tabluar format), things work
great. For the tabular data, I use the grid geometry, and simple
Tkinter calls. If RowsPerPage is set to 10, I can page through my
results, and the interior of the ScrolledFrame gets refreshed 
properly. However, if the data are displayed in Row (record format), 
I use PMW.Group to create my 'record or card' look and PMW.EntryField 
to display the fields in each 'record'.  With RowsPerPage=10, when
I press the 'nextpage' icon, instead of 'refreshing' what inside
the ScrollFrame interior, it 'appends' to it. 

Suggestions are greatly appreciated.
--irene barg
***code portions follow, not complete code, but may help***
	# build our results window
	self.megaTop = Pmw.MegaToplevel(parent,title=self.title,
					hull_background='white',
					hull_highlightbackground='white')      
	self.interior = self.megaTop.interior() 
		
	# Create the ScrolledFrame.
	self.sfheight = 200
	if self.rowspp > 10:  self.sfheight = 400
	self.sf = Pmw.ScrolledFrame(self.interior,
			labelpos='n',
			label_text=self.reslabel,
			label_background='white',
			label_foreground='black',
			usehullsize=1,
			horizflex='expand',
			frame_background='white',
			hull_width=600,
			hull_height=self.sfheight,
			hull_background='white',
			clipper_background='white')
	self.sf.configure(hscrollmode = 'dynamic')
	self.sf.configure(vscrollmode = 'dynamic')
	self.sframe = self.sf.interior()

	# add the CloseWindow button
	self.resultsbutBox =Pmw.ButtonBox(self.interior,
            hull_background='white',)
	self.resultsbutBox.add('CloseWindow',
            highlightbackground='white',
            background='lightgrey',
            foreground='black',command = self.megaTop.destroy)
	self.resultsbutBox.add('Help',
            highlightbackground='white',
            background='lightgrey',
            foreground='black',command=self.dohelp)
	if self.numpages > 1:
	    self.resultsbutBox.add('Start',image=self.BUT2L,
                highlightbackground='white',
                background='lightgrey',
                foreground='black',command = self.startpage)
  	    self.resultsbutBox.add('Prev',image=self.BUT1L,
                highlightbackground='white',
                background='lightgrey',
                foreground='black',command = self.prevpage)
 	    self.resultsbutBox.add('Next',image=self.BUT1R,
                highlightbackground='white',
                background='lightgrey',
                foreground='black',command = self.nextpage)
	    self.resultsbutBox.add('End',image=self.BUT2R,
                highlightbackground='white',
                background='lightgrey',
                foreground='black',command = self.endpage)

	self.resultsbutBox.pack(side='bottom',fill='x',padx=3,pady=3)
	self.sf.pack(padx = 5, pady = 5, fill = 'both', expand = 1)
 
......
    def showPage(self,pgdata):
    """ display result rows as defined by rows-per-page option."""
        if self.view == 'Columns':
	    # display tabular format (this works fine)
            # skip code here
   	else:
	    # dislay record format
	    rn = 0
	    for record in pgdata:
		resultgrp = Pmw.Group(self.sframe,
			tag_pyclass=eval(self.tagclass),				                       
tag_text=self.tagtext,
                        tag_command=self.selectRecord,
                        tag_variable=self.pickvar,							       
tag_value=rn,										tag_background='lightgrey',							       
tag_foreground='black',									hull_background='white',								hull_highlightbackground='lightgrey',							ring_highlightbackground='lightgrey',							ring_background='lightgrey',)
			resultgrp.pack(fill='both',expand=1,padx=2,pady=2)
		
            fields = []
  	    cn = 0
	    for col in self.columns:
		if (self.style == 'Compact') and (col in self.skipfields):
		    cn = cn + 1
		    continue
		field = Pmw.EntryField(resultgrp.interior(),								label 
pos='w',										label_text =
string.capitalize(col),							label_background='lightgrey',
				label_foreground='black',								hull_background='lightgrey',							
       hull_highlightbackground='lightgrey',
				value=record[cn],							               
entry_background='white',							       
entry_foreground='black',							        entry_state='disabled',							
               validate=None, command=None)
		if (self.action == 'Search') and (self.urlndx == cn):
		    field.configure(entry_foreground='blue',						       
entry_highlightbackground='lightgrey',							entry_relief='raised',)
		    field.component('entry').bind('<Double-Button-1>',
                        self.viewPublication)	
                
               field.pack(fill='x',expand=1)
	       fields.append(field)
	       cn = cn + 1
	       Pmw.alignlabels(fields)
	       rn = rn + 1




More information about the Python-list mailing list