I'm trying to understand what the fastest way is to add a bunch of strings that are pre-arranged in some fashion to a Listbox widget, so that every string is in a new line.
The quickest I could gather so far:
from Tkinter import *
strings= 'str1', 'str2', 'str3'
listbox=Listbox(None)
[listbox.insert(END, item) for item in strings]
listbox.pack()
Is there perhaps a cleaner faster way to get it done, without iterating over every string? Perhaps if the strings are pre-packed in a certain way or using some other method?
If it is of relevance, I want to use it to display directory listings.
A listbox shows a list of options. You can then click on any of those options. By default it won't do anything, but you can link that to a callback function or link a button click. To add new items, you can use the insert() method.
set () method of the horizontal scrollbar. Yscrollcommand - The yscrollcommand keyword used for the canvas is scrollable, this attribute must be the. set () method of the vertical scrollbar.
To edit the Listbox items, we have to first select the item in a loop using listbox. curselection() function and insert a new item after deleting the previous item in the listbox. To insert a new item in the listbox, you can use listbox. insert(**items) function.
This code inserts all strings in the collection:
listbox.insert(END, *strings)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With