gpt4 book ai didi

python - 计算适合 Tkinter 中列表框可视区域的项目数量

转载 作者:太空宇宙 更新时间:2023-11-03 15:45:59 25 4
gpt4 key购买 nike

我无法找到适合可视列表框区域的列表框项目数量,因此您无需向下滚动。抱歉,如果这是微不足道的,我很难弄清楚这一点。

我写了一个小例子来说明我的问题:

from Tkinter import *
from tkFont import Font

myfont=Font(family='Times', size=12)

a=Listbox(activestyle='dotbox', font=myfont)
a.insert(END, *xrange(100))
a.pack(side='left', fill=BOTH, expand=1)

mainloop()

现在我有一个列表框,但只有其中的一些项目可见。如何计算在不超出可视区域的情况下可以容纳多少个?任何见解都将受到欢迎。谢谢!

最佳答案

tkFont 高度的大小存储在 linespace 指标中,可通过 metrics() 方法访问 -

myfont.metrics()['linespace']
#returns 19 for myfont as initiated in the question

列表框小部件的高度可通过 winfo_height() 检索。总共 -

visible_lines= a.winfo_height()/myfont.metrics()['linespace']

资源 - http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/fonts.html

关于python - 计算适合 Tkinter 中列表框可视区域的项目数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41750645/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com