Rewrite the Python program of Fig. 11.2. Create a multiple-selection list of colors. Al- low the user to select one or more colors and copy them to a ScrolledText component.

What will be an ideal response?

```
# Creating a multiple selection list.

from Tkinter import *
import Pmw

class ChoiceBox( Frame ):
"""Demonstrate multiple-selection lists"""

def __init__( self, listItems ):
"""Create multiple-selection list, Button and
ScrolledText"""

Frame.__init__( self )
Pmw.initialise()
self.pack( expand = YES, fill = BOTH )
self.master.title( "Select colors" )

# create a multiple-selection scrolled list box
self.listBox = Pmw.ScrolledListBox( self, items =
listItems, listbox_height = 5, vscrollmode = "static",
listbox_selectmode = MULTIPLE )
self.listBox.pack( side = LEFT, expand = YES, fill = BOTH,
padx = 5, pady = 5 )

self.copyButton = Button( self, text = "Copy >>>",
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 ):
"""Insert each selected item into ScrolledText"""

self.chosen.clear() # clear contents of chosen
selected = self.listBox.getcurselection()

if selected:

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

def main():
colorNames = ( "cyan", "green", "grey", "magenta",
"orange", "pink", "red", "white", "yellow" )
ChoiceBox( colorNames ).mainloop()

if __name__ == "__main__":
main()
```
![15068|248x91](upload://uDJji9UZsri22bBjYsREFEFkdvM.png)

Computer Science & Information Technology

You might also like to view...

Which option secures a wireless access point the most for a Windows 7 client?

A) WEP B) No SSID broadcasting C) MAC filtering D) Shared key authentication

Computer Science & Information Technology

Write a function to create a movie where one item is moving from the top to the bottom and another item is moving from the bottom to the top.

What will be an ideal response?

Computer Science & Information Technology