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. 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, bor开发者_如何学编程derwidth=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.
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.
精彩评论