调整窗口大小时调整Tkinter Listbox窗口小部件的大小 [英] Resize Tkinter Listbox widget when window resizes
问题描述
我是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.
推荐答案
您想阅读几何管理器 pack 和网格,可让您将窗口小部件放置在窗口中并指定它们是否生长与否.还有第三个几何管理器,地方,但是它并不经常使用.
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.
这是一个简单的例子:
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()
这篇关于调整窗口大小时调整Tkinter Listbox窗口小部件的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!