如何在 Tkinter 中获得带有滚动条的框架?
我想要一个 Frame
,用户可以在其中添加应用程序所需的任意数量的文本字段。
该应用程序以一个文本字段和该文本字段下方的一个按钮开始。当用户按下按钮时,新的文本条目将添加到第一个文本条目下方(这可能会重复无数次)。在窗口的中间,会有一个 Text
小部件,用于显示文本:)
但是,我在文档中注意到了这一点:
这个小部件用于实现滚动列表框、画布、和文本字段。
有没有办法将Scrollbar
与Frame
一起使用?
I'd like to have a Frame
, where the user could add as many textfields as needed by the application.
The application starts with a textfield, and a button below that textfield. When the user presses the button, a new text entry will be added below the first one ( this may be repeated countless times ). In the middle of the window, there will be a Text
widget, used to display text :)
However, I noticed this in the documentation:
This widget is used to implement scrolled listboxes, canvases, and text fields.
Is there a way to use the Scrollbar
with a Frame
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您可以使用 Tix,则可以使用 ScrolledWindow 小部件,它具有一个
window
Frame 和一两个 Scrollbar 小部件:更改根窗口的大小。您需要将代码添加到 Entry 小部件的 focus_get 事件中,以便在通过键盘进行 Tab 键操作时滚动 ScrolledWindow。
否则,您将不得不使用 Canvas 小部件(您可以添加标签、条目和文本子小部件)并自己编写更多代码来实现您所需的功能。
If you can use Tix, there is the ScrolledWindow widget which has a
window
Frame and one or two Scrollbar widgets:Change the size of the root window. You will want to add code to the focus_get event of the Entry widgets to scroll the ScrolledWindow when tabbing through the keyboard.
Otherwise, you will have to use a Canvas widget (you can add Label, Entry and Text subwidgets) and write a lot more code yourself to implement your required functionality.
以下是自动隐藏滚动条的示例,仅当您仅使用网格几何管理器时才有效,取自
effbot.org
文档:The following is an example of auto hiding scrollbars that only works if you just use the grid geometry manager, taken from the
effbot.org
documentation: