有没有办法在初始化时缩小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)
Run Code Online (Sandbox Code Playgroud)
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)
Run Code Online (Sandbox Code Playgroud)
编辑上面的示例是针对Python 2的。如果您使用的是Python 3,我相信现在from tk import font和导入/使用字体实用程序的正确方法small_font = font.Font(...)。