python listbox大小_调整窗口大小时调整Tkinter Listbox小部件的大小

I'm new to Tkinter, and I've got a Listbox widget that I'd like to automatically-resize when changing the main window's size.

Essentially I would like to have a fluid height/width Listbox. If someone can point me to some documentation or provide a bit a code / insight, I'd appreciate it.

解决方案

You want to read up on the geometry managers pack and grid, which lets you place widgets in a window and specify whether they grow and shrink or not. There's a third geometry manager, place, but it's not used very often.

Here's a simple example:

import Tkinter as tk

root = tk.Tk()

scrollbar = tk.Scrollbar(root, orient="vertical")

lb = tk.Listbox(root, width=50, height=20, yscrollcommand=scrollbar.set)

scrollbar.config(command=lb.yview)

scrollbar.pack(side="right", fill="y")

lb.pack(side="left",fill="both", expand=True)

for i in range(0,100):

lb.insert("end", "item #%s" % i)

root.mainloop()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值