FAQ
I've been trying to understand nearest(y) but I'm not getting it. I
have a ScrolledListBox with a list of people's names. I also have a
parallel list of the unique people numbers used in the PostgreSQL
database. When a name is selected from the scrolled list, I need to
determine the index value and then find the corresponding people number.


def selectionCommand(self):
sels = self.box.getcurselection()
if len(sels) == 0:
print 'No selection'
else:
print 'Selection:', sels[0]
print self.nmbr_list[self.box[0].nearest(y)]
self.lkupTopLevel.withdraw()

Where do I obtain the value y used in nearest(y)?

--
---------------------------------------------------------------------
Scott Holmes http://sholmes.ws
http://pages.sbcglobal.net/scottholmes
scottholmes at sbcglobal.net

Independent Programmer/Analyst Passport 4GL
PHP HTML Composer PostgreSQL Informix 4GL, SQL
---------------------------------------------------------------------
There are more things in heaven and earth, Horatio,
than are dreamt of in your philosophy
---------------------------------------------------------------------

Search Discussions

  • Daniel P. Engel at Aug 5, 2003 at 4:10 pm
    Where do I obtain the value y used in nearest(y)?
    Wouldn't that be sels[0]?

    Scott Holmes wrote:
    I've been trying to understand nearest(y) but I'm not getting it. I
    have a ScrolledListBox with a list of people's names. I also have a
    parallel list of the unique people numbers used in the PostgreSQL
    database. When a name is selected from the scrolled list, I need to
    determine the index value and then find the corresponding people number.


    def selectionCommand(self):
    sels = self.box.getcurselection()
    if len(sels) == 0:
    print 'No selection'
    else:
    print 'Selection:', sels[0]
    print self.nmbr_list[self.box[0].nearest(y)]
    self.lkupTopLevel.withdraw()

    Where do I obtain the value y used in nearest(y)?
  • Scott Holmes at Aug 5, 2003 at 5:45 pm

    Daniel P. Engel wrote:
    Wouldn't that be sels[0]?
    The value in sels[0] is the string I wish to display in a label, not the
    row number. Actually I've abandoned the attempt to find the row number.
    I'm now creating a dictionary at the same time the listbox is being
    populated:

    while 1:
    lRec = curs.fetchone()
    if not lRec: break

    itm = str(lRec[3]) + ", " + str(lRec[1]) + " " + str(lRec[2])
    self.box.insert('end', itm)
    self.pnmbrs[itm] = str(lRec[0])

    The select statement fetches the unique people_nmbr and the person's
    first middle and last name. The listbox displays the name value,
    thusly: last_name, first_name middle_name.
    When a row is selected from the listbox, the selected value is used as a
    key:

    def selectionCommand(self):
    sels = self.box.getcurselection()
    if len(sels) == 0:
    print 'No selection'
    else:
    print 'Selection:', sels[0]
    print 'People Number:', self.pnmbrs[sels[0]]



    If there is a prefered or more efficient way of doing this, I would be
    grateful to hear of it.

    --
    ---------------------------------------------------------------------
    Scott Holmes http://sholmes.ws
    http://pages.sbcglobal.net/scottholmes
    scottholmes at sbcglobal.net

    Independent Programmer/Analyst Passport 4GL
    PHP HTML Composer PostgreSQL Informix 4GL, SQL
    ---------------------------------------------------------------------
    There are more things in heaven and earth, Horatio,
    than are dreamt of in your philosophy
    ---------------------------------------------------------------------

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedAug 5, '03 at 12:13a
activeAug 5, '03 at 5:45p
posts3
users2
websitepython.org

2 users in discussion

Scott Holmes: 2 posts Daniel P. Engel: 1 post

People

Translate

site design / logo © 2022 Grokbase