Python tk 滚动框架?

发布于 2024-10-09 05:23:39 字数 482 浏览 0 评论 0原文

我正在使用 Tkinter 和 Python 创建一个简单的 GUI 应用程序,但在向单个框架添加滚动条时遇到问题。在我的 20" 上,该框架从上到下可见,但为了在上网本或任何其他低分辨率屏幕上显示所有内容,它需要一个滚动条。以下是我认为它如何工作的片段(它适用于列表框)

framelist = Tkinter.Frame(self.pmaster, relief=FLAT, borderwidth=0)
framelist.pack(fill=BOTH, padx=0, pady=0)
yscroll = Tkinter.Scrollbar(framelist, width=10, orient=VERTICAL)
yscroll.pack(fill=Y,side=RIGHT,padx=0,pady=0)

。这显然不适用于框架。

我也想知道 Tkinter 是否已经过时了,但那是几年前的事了。顺便说一句,它已经不能满足我的要求了,肯定有更好的选择吗?

I'm creating a simple GUI app using Tkinter with Python, but I'm having problems adding a scrollbar to a single frame. The frame is visible from top to bottom on my 20" but in order to display everything on a netbook or any other low res screen it needs a scrollbar. Here's a snippet of how I thought it would work (it does with listboxes).

framelist = Tkinter.Frame(self.pmaster, relief=FLAT, borderwidth=0)
framelist.pack(fill=BOTH, padx=0, pady=0)
yscroll = Tkinter.Scrollbar(framelist, width=10, orient=VERTICAL)
yscroll.pack(fill=Y,side=RIGHT,padx=0,pady=0)

Though this doesn't work with frames apparently. Any help on this issue from you guys will be deeply appreciated!

I'm also wondering if Tkinter might be outdated. It was the only GUI interface I learned in school, but thats several years ago and it doesn't really meet my demands anymore. Surely there must be a better alternative? I'm on Ubuntu btw.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦太阳 2024-10-16 05:23:39

tkinter 的框架小部件不滚动。一种解决方案是将整个框架放入画布中(作为画布对象),并将滚动条附加到画布上。您必须告诉画布可滚动区域有多大,可以通过在将所有小部件放入其中后获取框架的大小来实现。不过,您可能需要重新考虑您的 UI 设计——无论您使用什么 GUI 工具包,可滚动框架都不是很容易使用。

至于Tkinter是否过时……有人说是,有人说不是。那里有很多 tkinter 错误信息,所以对所有 tkinter 意见持保留态度(甚至是我的!)。 Tkinter 不断改进,并没有停滞不前。如果您有幸使用 python 2.7 或更高版本,您可以访问 ttk 小部件,它提供特定于平台的主题和其他小部件,例如笔记本和分层树等。

对于替代方案,您可能想查看 wxPython。根据我的经验,它似乎比 tkinter 有更多的错误和怪癖,但有更多的小部件,并且似乎更受欢迎。

我喜欢认为 tkinter 和 wxPython 之间的区别就像 Home Depot(一家家居装修/腰院商店)和 Ikea(您自己组装的预制家具)之间的区别 - 一个为您提供了制作所需的所有零配件任何你想要的东西(tkinter)另一个给你很多预先打包的东西。每种方法都有其优点和缺点。

The frame widget of tkinter doesn't scroll. One solution is to put your whole frame in a canvas (as a canvas object), and attach the scrollbar to the canvas. You have to tell the canvas how big the scrollable area is, which you can do by getting the size of the frame once you've placed all the widgets in it. Though, you might want to reconsider your UI design -- scrollable frames aren't very easy to use no matter what GUI toolkit you use.

As for whether Tkinter is outdated... some say yes, some say no. There is a lot of tkinter misinformation out there so take all tkinter opinions with a grain of salt (even mine!). Tkinter continues to improve, it hasn't stagnated. If you have the luxury of using python 2.7 or greater you have access to the ttk widgets which offer platform-specific themes and additional widgets such as a notebook and hierarchical tree among others.

For alternatives you might want to check out wxPython. In my experience it seems to have considerably more bugs and quirks than tkinter, but has a lot more widgets and seems to be more popular.

I like to think that the difference between tkinter and wxPython is like the difference between Home Depot (a home improvement / lumbar yard store) and Ikea (prefabricated furniture that you assemble yourself) - one gives you all the bits and pieces to make just about anything you want (tkinter) the other gives you a lot of pre-packaged stuff. Each approach has its strengths and weaknesses.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文