Is there a way to shrink the height of the cells of TKinter listbox at initialization?
self.lb = Listbox(f,selectmode=MULTIPLE, bd=1, height=10)
self.lb.bind("<<ListboxSelect>>", self.onSelectlbItem)
self.lb.grid(row=3, column=1,columnspan=7, sticky="WE", pady=0)
The height of the rows in a tkinter listbox is dependent on the size of the text font. This can be set for the whole widget (although not for individual rows), either as the font=
optional argument at initialization, or using the .config
method of the listbox post-initiatlization.
Below is how the code might look if you do the font-size setting at initialization time:
import tkFont
small_font = tkFont.Font(size=5) # Specify font size, and use default style for other parameters
self.lb = Listbox(f,selectmode=MULTIPLE, bd=1, height=10, font=small_font)
Edit The above example is for Python 2. If you are using Python 3, I believe the correct way to import/use the font utilities is now from tk import font
and small_font = font.Font(...)
.
The height of the rows do depend on the font size, but there is an easier way to change the font size without the need to import anything:
self.lb = Listbox(f,selectmode=MULTIPLE, bd=1, height=10, font=('Times', 14))
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