Tkinter listbox:get

Discussion in 'Python' started by vedran_dekovic@yahoo.com, Sep 7, 2006.

  1. Guest

    Hi,
    I need help about Tkinter.I want,when somebody click on some item in
    listbox,then
    in new entry widget must write that item

    Regards,
    Vedran
     
    , Sep 7, 2006
    #1
    1. Advertising

  2. <> Wrote:


    | Hi,
    | I need help about Tkinter.I want,when somebody click on some item in
    | listbox,then
    | in new entry widget must write that item
    |
    | Regards,
    | Vedran

    I have already covered the retrieval from the listbox in another thread.
    You can set the entry box contents like this:

    NameOfStringForEntryboxContents = StringVar()

    Then in your definition of the Entry box, add in:

    textvariable = NameOfStringForEntryboxContents

    and when you have retreived the listbox entry:

    NameOfStringForEntryboxContents.set(NameOfStringWithListboxStuff)

    and it will appear in your entry field...

    HTH
    -Hendrik
     
    Hendrik van Rooyen, Sep 8, 2006
    #2
    1. Advertising

  3. <> wrote in email:


    | Hi,and sorry I forget tell you what I want exactly.
    |
    | My problem is
    |
    | example:
    |
    | when I write like you tell me:
    |
    | >>> idx=lb.curselection()
    | >>> StringValue=lb.get(idx) <======= This


    |
    | ....THEN,ERROR IS:
    |
    | Traceback (most recent call last):
    | File "<pyshell#18>", line 1, in -toplevel-
    | StringValue=b.get(idx) <========== is not the same as this



    | File "C:\Python24\lib\lib-tk\Tkinter.py", line 2432, in get
    | return self.tk.call(self._w, 'get', first)
    | TclError: bad listbox index "": must be active, anchor, end, @x,y, or a
    | number
    |
    | ...which index I must write to listbox get just clicked row.
    |
    |
    | THANKS!!!!!!!!
    |

    Just use the print statement to see what is going on - use :

    print idx

    after getting the idx with the curselection - it must be the number of the row
    that
    was clicked

    - Hendrik
     
    Hendrik van Rooyen, Sep 9, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. blenderdude
    Replies:
    0
    Views:
    1,104
    blenderdude
    Aug 3, 2003
  2. DC Gringo
    Replies:
    0
    Views:
    413
    DC Gringo
    Apr 6, 2004
  3. kent
    Replies:
    1
    Views:
    891
    Andrew de la Harpe
    May 3, 2004
  4. Simon Prince
    Replies:
    2
    Views:
    3,355
    =?Utf-8?B?TWljaGFlbCBUYXlsb3I=?=
    Oct 19, 2004
  5. Replies:
    6
    Views:
    608
    Hendrik van Rooyen
    May 31, 2007
Loading...

Share This Page