How to use the Tkinter list box control Listbox
This article mainly explains the "Tkinter list box control Listbox how to use", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Tkinter list box control Listbox how to use" it!
The first step is to build the Listbox control and add list items:
# create a listbox for demo.lb = Listbox (root, activestyle='dotbox', bg= "# ffffa0", fg= "# ff0000", disabledforeground= "# 3f3f3f", highlightbackground= "# 0000ff", font=ftiTimes, height=10, width=20)
# add itemsfor i in range (0jue 20): lb.insert (END, str (I))
The list box control does not provide a command property to specify the event handler, which is implemented using the bind "ListboxSelect" event. The content of the event handling is specified by the lambda expression, which avoids implementing a function that is only used once and is too simple.
# bind eventlb.bind ('', lambda e: label.config (text=str (lb.curselection () lb.grid (row=0, column=0, columnspan=3, sticky=W+E)
Build three Spinbox controls to modify valid / invalid, selected item representation and selection mode properties, respectively.
# create a Spinbox to change state.st_spin = Spinbox (root, values= ('normal',' disabled'), state='readonly', command=lambda:lb.config (state=st_spin.get ()) st_spin.grid (row=1, column=0, columnspan=1, sticky=W)
# create a Spinbox to change activestyle.as_spin = Spinbox (root, values= ('dotbox',' underline', 'none'), state='readonly', command=lambda:lb.config (activestyle=as_spin.get ()) as_spin.grid (row=1, column=1, columnspan=1, sticky=W)
# create a Spinbox to change select mode.sm_spin = Spinbox (root, values= ('browse',' single', 'multiple',' extended'), state='readonly', command=lambda:lb.config (selectmode=sm_spin.get ()) sm_spin.grid (row=1, column=2, columnspan=1, sticky=W)
Finally, a tag is built to represent the selection.
Label=Label (root) label.grid (row=2, column=0, columnspan=4) Thank you for your reading, this is the content of "how to use Tkinter list box control Listbox". After the study of this article, I believe you have a deeper understanding of how to use Tkinter list box control Listbox, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!