Creating a multiple selection list. : ListBox « Tkinker « Python Tutorial






Creating a multiple selection list.
from Tkinter import *
import Pmw

class choiceBox( Frame ):
   def __init__( self, listItems ):
      Frame.__init__( self )
      self.pack( expand = YES, fill = BOTH )
      self.master.title( "Select" )

      self.listBox = Pmw.ScrolledListBox( self,
                                          items = listItems,
                                          listbox_height = 5,
                                          vscrollmode = "static",
                                          listbox_selectmode = EXTENDED )
      self.listBox.pack( side = LEFT, expand = YES, fill = BOTH,padx = 5, pady = 5 )

      self.copyButton = Button( self,text = ">>>", command = self.addColor )
      self.copyButton.pack( side = LEFT, padx = 5, pady = 5 )

      self.chosen = Pmw.ScrolledText( self,text_height = 6,text_width = 20 )
      self.chosen.pack( side = LEFT, expand = YES, fill = BOTH,padx = 5, pady = 5 )

   def addColor( self ):
      self.chosen.clear()
      selected = self.listBox.getcurselection()

      if selected:
         for item in selected:
            self.chosen.insert( END, item + "\n" )

colorNames = ( "A", "B", "C", "D")
choiceBox( colorNames ).mainloop()








18.19.ListBox
18.19.1.Add item to ListBoxAdd item to ListBox
18.19.2.ListBox with scroll barListBox with scroll bar
18.19.3.Creating a multiple selection list.Creating a multiple selection list.
18.19.4.Add item to the end of ListBoxAdd item to the end of ListBox
18.19.5.Remove the selected itemsRemove the selected items
18.19.6.Scrolled listScrolled list