2021年1月20日星期三

empty listbox return values with python 3.7 tkinter

why is this listbox not returning my selection? I added the returnSelected() function with a button thinking that it needed to be triggered. My goal is to create as simple a possible function that a user can select a reduced list, and I am clearly not understanding the tkinter flow.

import tkinter  def listboxinput3():      # <ListboxSelect> callback function and current selection      def cb(event):          label['text'] = str(event) + '\n' + str(lb.curselection())        def returnSelected():          myselection = [my_list[k] for k in lb.curselection()]          print(myselection )        root = tkinter.Tk()      root.title('Parameter Selection')      root.geometry('200x600')      my_list = dir(tkinter)      var = tkinter.StringVar(value=my_list)        label = tkinter.Label(root)      label.grid()      btnGet = tkinter.Button(root,text="Get Selection",command=returnSelected)      btnGet.grid()      lb = tkinter.Listbox(root, listvariable=var, selectmode='extended')      lb.grid()      lb.bind('<<ListboxSelect>>', cb)      #tkinter.Button(root, text="Show Selected", command=returnSelected).pack()      selected_text_list = [lb.get(i) for i in lb.curselection()]      root.mainloop()      return selected_text_list    selected_text_list = listboxinput3()  

Thanks

https://stackoverflow.com/questions/65819932/empty-listbox-return-values-with-python-3-7-tkinter January 21, 2021 at 09:23AM

没有评论:

发表评论