[Tutor] tkinter listbox function

Alan Gauld alan.gauld at yahoo.co.uk
Tue Oct 26 05:42:42 EDT 2021


On 26/10/2021 01:08, Ed Connell wrote:
> Hi again,
> 
> HELP!!!
> 
> I really, really, really want to know how to implement this function using
> a Tkinter Lisbox.
> 
> def pickFromListTK( listOfChoices ):
> 
>    ---
> 
>     some code using a Listbo:
> 
>    ---
> 
>     return choice


It is not at all clear what you want the function to do.
Can you describe what the user would do to activate this
function and what the result would be?

If you just want the index of the selected item(or items
since there could be more than one) within the list
then the Listbox has a method for that, you don't need
to write a function.

eg:

class MyGUI(Frame):
   def __init__(self,parent):
      .... # build GUI
      self.myListbox = tkinter.Listbox(....)
      ...
      tkinter.Button(self, text="OK", command=self.handle_OK_button)
      ...

   def handle_OK_Button(self):
       selected = self.myListbox.curselection()
       for index in selected:
           item = self.myListbox.get(index)
           ... # process item here.


But unless you explain more about what the function is
supposed to do we can't really help. It may seem obvious
to you but it isn't to us!

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list