Pmw.ScrolledListbox

Era Akost era_akost at yahoo.de
Thu Nov 15 12:29:02 EST 2001


Martin Franklin <martin.franklin at westgeo.com> wrote in message news:<9t04c2$53ra$1 at mail1.wg.waii.com>...

> Era,
> 
> Could you post some code I can't see this with the following code....
> 
> >>> from Tkinter import *
> >>> import Pmw
> >>> root=Tk()
> >>> lb=Pmw.ScrolledListBox(root)
> >>> lb.pack()
> >>> lb.insert(0, 'one')
> >>> lb.insert(0, 'two')
> >>> lb.insert(0, 'three')
> 
> Oh and what platform/version etc....
> 
> Martin

Hi Martin, 

you're wright. This code doesn't show what I was talking about. I
tried myself several from these simple examples and no one show an
underlined item selection. In fact, my code is a little more
complicated. I will paste it at the end of the message.

I create a class SelectionWindow - which has a Pmw.SelectionDialog
(one of which components is Scrolledlist). I need this class because
in my application I'll be calling several times the SelectionDialog,
with different items.
To show how it is called in my application, I wrote a simple class
Demo.

Making some tests now, it seems that the problem is connected to the
functions
withdraw(), activate(). I have no idea why.

I'm using Python 2.0 on Windows NT.

Here is the code. It runs.
######################################

from Tkinter import *
import Pmw

class SelectionWindow:
    def __init__(self, parent, data = ()):
        self.data = data
        self.dialog = Pmw.SelectionDialog(parent,
                             title = 'Selection Window',
                             buttons = ('Accept Selection', \
                                        'Undo Selection'),
                             defaultbutton = 'Accept Selection',
                             scrolledlist_labelpos = 'nw',
                             label_text = "Make your selection",
                             scrolledlist_items = self.data,
                             command = self.selected)
        
        self.dialog.withdraw()

    def activate(self, data = ()):
        if data:
            self.data = data
        self.dialog.setlist(self.data)
        self.dialog.activate()
        return self.dialog.getcurselection()

    def selected(self, result):
        if result == 'Accept Selection':
            self.dialog.deactivate()
        else:
            self.dialog.selection_clear()

data = ('January', 'February', 'Mars', 'April', 'May', 'June')


class Demo:
    def __init__(self, parent):
        self.var = StringVar()
        Button(parent, text = 'Select Fields',
               command = self.call_sw).pack(padx = 10,
                                            pady = 10, side = LEFT)
        Label(parent, textvariable = self.var,
              width = 10).pack(padx = 10, pady = 10, side = RIGHT)
        self.sw = SelectionWindow(parent)
        #uncomment last line,
        #while commenting self.dialog.withdraw() above
        #self.sw = SelectionWindow(parent, data)    

    def call_sw(self):
        selection = self.sw.activate(data)[0]   #result is a tuple
        self.var.set(selection) #set the value to the lable text

if __name__ == '__main__':
    root = Tk()
    root.title('Demo Test')
    d = Demo(root)
    root.mainloop()



More information about the Python-list mailing list