[Tutor] populating a listbox from a list

Max Russell max_russell2000 at yahoo.co.uk
Fri Jul 15 21:08:34 CEST 2005


Hello-

I have a list in this format:

puckman   puckmana  puckmanf  puckmanh  pacman   
pacmanf   puckmod   pacmod  
newpuc2   newpuc2b  newpuckx  pacheart  hangly   
hangly2   hangly3   piranhah
crush     crush2    crush3    maketrax  maketrxb 
korosuke  mbrush    paintrlr
pacplus   joyman    ctrpllrp  eyes      eyes2    
mrtnt     gorkans   eggor   
jumpshot  jumpshtp  shootbul  piranha   piranhao 
nmouse    nmouseb   mspacman
mspacmnf  mspacmat  woodpek   woodpeka  mspacmab 
pacgal    mspacpls  ponpoko 
ponpokov  lizwiz    alibaba   dremshpr  vanvan   
vanvank   vanvanb   bwcasino

and I want to use it to populate a TK listbox:

 def create_widgets(self):
        """ Create button, text, and entry widgets.
"""
        # create instruction label
        self.inst_lbl = Label(self, text = "Please
select a game")
        self.inst_lbl.grid(row = 0, column = 0,
columnspan = 2, sticky = W)

        # create label for password      
        self.pw_lbl = Label(self, text = "Click OK
when ready ")
        self.pw_lbl.grid(row = 12, column = 0, sticky
= W)
        
        #create the scrollbar for the listbox
        self.yScroll = Scrollbar ( self,
orient=VERTICAL )
        self.yScroll.grid ( row=1, column=1,
sticky=N+S )

        # create listbox to list games
        self.lstbx =Listbox(self, height = 20,
yscrollcommand=self.yScroll.set
highlightcolor="yellow")
        self.lstbx.grid(row = 1, column = 0,sticky=W)
        #lock the vertical scroll to the listbox.
        self.yScroll["command"] = self.listbox.yview
        
        # create ok button
        self.submit_bttn = Button(self, text = "OK",
command = self.launchmame)
        self.submit_bttn.grid(row = 12, column = 1,
sticky = W)

        # create quit button
        self.submit_bttn = Button(self, text = "Quit",
command = self.quit)
        self.submit_bttn.grid(row = 12, column = 2,
sticky = W)

I'm really not sure how to populate the list though- I
can work with lists just as text, but what do I need
to do to read a list into a listbox.

Should I preformat the list I read from to be one
entry per line?

I don't know if I want to pickle my data as i need to
be able to delete defunct list entries from my little
GUI application.

thanks
Max


	
	
		
___________________________________________________________ 
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com


More information about the Tutor mailing list