Tkinter 中复选框的可变大小列表?
我正在执行一项编程任务。我正在使用 Python
工作,并使用 Tkinter
作为我们的 GUI。我无法更改语言或 GUI 工具,也无法使用任何其他软件包(例如 Tix
)。
我需要列出要拉的项目清单。我首先想到的是复选框。然而,据我所知,Tkinter 没有任何支持大量(100+)复选框的东西。该数字不是恒定的,并且可能会随着程序的每次运行而不同。在他们自己的框架中,我还没有找到使框架可滚动的方法。我尝试了Listbox
,但是没有好的方法可以在此范围内选择多个。
你们中有人知道有办法做到这一点吗?
I'm working on a programming task. I'm working in Python
, and using Tkinter
for our GUI. I cannot change language or GUI tool, nor can I use any additional packages (for example Tix
).
I need to make a list of items to pull. The first thing I thought of was a check box. However, so far as I know, Tkinter does not have anything that supports a large number(100+) of check boxes. The number is not constant, and likely will be different with every run of the program. In their own frame, I have not found a way to make the frame scrollable. I tried Listbox
, but there is no good way to select multiples on this scale.
Do any of you know of a way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Tkinter 支持相对无限数量的复选框,主要受到系统内存和可用性限制等实际问题的限制。
至少有三种技术可以用来制作小部件的可滚动容器。画布和文本小部件都支持滚动,因此普遍接受的做法是将其中之一用于容器。如果您需要复杂的东西,您还可以使用 place 命令来实现一些巧妙的技巧。
如果您想要滚动包含多个对象的垂直列表的框架,那么使用画布是很好的选择。如果您只需创建一个垂直列表,那么使用文本小部件会非常方便。
这是一个简单的示例:
当您了解有关 Tkinter 的更多信息时,您会意识到它的内置小部件并不像其他一些工具包那么多。希望您还会意识到 Tkinter 拥有足够的基本构建块来完成您可以想象的任何事情。
Tkinter supports a relatively unlimited number of checkboxes, limited mostly by practical matters such as system memory and usability constraints.
There are at least three techniques for making a scrollable container for widgets. Both canvases and text widgets support scrolling, so the generally accepted practice is to use one of those for the container. You can also do clever tricks with the place command if you need something complex.
Using the canvas is good if you want to scroll a frame that contains more than just a vertical list of objects. Using the text widget is quite handy if all you need to do is create a single vertical list.
Here's a simple example:
As you learn more about Tkinter you'll realize that there aren't quite as many built-in widgets as some other toolkits. Hopefully you'll also realize that Tkinter has enough fundamental building blocks to do just about anything you can imagine.