有没有办法在初始化时缩小TKinter列表框的单元格的高度?
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)
tkinter列表框中的行的高度取决于文本字体的大小。可以为整个窗口小部件(尽管不是为单个行)设置此参数,既可以将其设置为font=
初始化时的可选参数,也可以使用初始化.config
后的列表框的方法来设置。
如果在初始化时进行字体大小设置,则代码如下所示:
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)
编辑上面的示例适用于Python2。如果您使用的是Python 3,我相信现在from tk import font
和现在导入/使用字体实用程序的正确方法small_font = font.Font(...)
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句