简体   繁体   English

Python tk滚动框架?

[英]Python tk scroll frame?

I'm creating a simple GUI app using Tkinter with Python, but I'm having problems adding a scrollbar to a single frame. 我正在使用Tkinter和Python创建一个简单的GUI应用程序,但是我在向单个框架添加滚动条时遇到了问题。 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). 框架在我的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)

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. 我也想知道Tkinter是否会过时。 It was the only GUI interface I learned in school, but thats several years ago and it doesn't really meet my demands anymore. 这是我在学校学到的唯一一个GUI界面,但几年前就已经不再符合我的要求了。 Surely there must be a better alternative? 当然必须有更好的选择吗? I'm on Ubuntu btw. 我在Ubuntu顺便说一下。

The frame widget of tkinter doesn't scroll. tkinter的框架小部件不会滚动。 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. 但是,您可能想重新考虑您的UI设计 - 无论您使用哪种GUI工具包,可滚动框架都不是很容易使用。

As for whether Tkinter is outdated... some say yes, some say no. 至于Tkinter是否过时......有人说是,有些人说不。 There is a lot of tkinter misinformation out there so take all tkinter opinions with a grain of salt (even mine!). 那里有很多tkinter错误的信息,所以拿出所有的tkinter意见(即使是我的!)。 Tkinter continues to improve, it hasn't stagnated. Tkinter继续改进,它并没有停滞不前。 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. 如果您可以使用python 2.7或更高版本,则可以访问ttk小部件,这些小部件提供特定于平台的主题和其他小部件,例如笔记本和分层树等。

For alternatives you might want to check out wxPython. 对于替代方案,您可能需要查看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. 根据我的经验,它似乎比tkinter有更多的错误和怪癖,但有更多的小部件,似乎更受欢迎。

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. 我觉得tkinter和wxPython之间的区别就像Home Depot(一个家居装修/腰部商店)和Ikea(你自己组装的预制家具)之间的区别 - 一个给你所有的点点滴滴任何你想要的东西(tkinter)另一个给你很多预包装的东西。 Each approach has its strengths and weaknesses. 每种方法都有其优点和缺点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM