For the use of the listbox for the Python Tkinter component, see the following code for a demonstration:
1 fromTkinterImport*2 3root=Tk ()4v=Stringvar ()5 #ListBox and variable binding '6Lb1=listbox (root,listvariable=v)7V.set (('Ten',' -',' -',' +',' -'))8 Print(V.get ())9 Lb1.pack ()Ten One #. Create a ListBox with multiple selections, using the attribute selectmaod ' ALb2=listbox (root,selectmode=multiple) - forIteminchRange (10): - Lb2.insert (END,STR (item)) the #There are two special values for active and end,active that are inserted before the currently selected item. - #(that is, use the currently selected index as the insertion position); - #the last item in the listbox is added to insert an item - +Lb2.delete (1,3) - #Delete all content, using Delete to specify the first index value 0 and the last parameter end, you can + Lb2.pack () A at #This property SelectMode can also be set to browse, which can be moved by mouse to the selected position in the listbox - #(not move item), - #This property is also the value of the ListBox in the default setting, which is the same as the result of the program running 1. -Scrollbar=Scrollbar (Root) -Scrollbar.pack (side=right,fill=Y) -Lb3=listbox (root,selectmode=browse,yscrollcommand=scrollbar.set) in forIteminchRange (20): - Lb3.insert (END,STR (item)) toLb3.pack (side=left,fill=BOTH) +Scrollbar.config (command=Lb3.yview) - the #combine these controls in a vertically oriented scrollbar and Listboxs/canvases/text fields . * #you just need to follow the steps below: $ #1. Set the Yscrollcommand option for these controls to the set method of ScrollBar. Panax Notoginseng #2. Set the command option for ScrollBar to the Yview method for these controls. - the Print(Lb3.size ()) + Print(Lb3.get (3)) A Print(Lb3.get (3,7)) theLb3.selection_set (0,10) +Lb3.selection_clear (0,3) - Lb3.pack () $ $ - defPrintlist (event): - Print(Lb4.get (Lb4.curselection ())) the - Wuyi #Use SelectMode = expanded to support shift and control using a ListBox theLb4=listbox (root,selectmode=EXTENDED) -Lb4.bind ('<Double-Button-1>', Printlist) Wu forIteminch['python','Tkinter','Widgets']: - Lb4.insert (End,item) About Lb4.pack () $ - -Root.mainloop ()
Python tkinter ListBox usage