views:

1531

answers:

4
+2  Q: 

Tabs in Tkinter

Having played around a little with both Tkinter and wxPython, I like Tkinter much better in terms of how clean my source code looks. However, it doesn't seem to have as many features; in particular it doesn't have tabs (as in, the tabs at the top of a Firefox window).

A little Googling on the subject offers a few suggestions. There's a cookbook entry with a class allowing you to use tabs, but it's very primitive. There's also Python megawidgets on SourceForge, although this seems very old and gave me errors during installation.

Does anyone have experience making tabbed GUIs in Tkinter? What did you use? Or is it simply the case that anyone who needs more powerful windowing components has to use wxPython?

+1  A: 

"Or is it simply the case that anyone who needs more powerful windowing components has to use wxPython?"
Short answer: yes.

Long answer: It may take some practice for your wxPython code to feel "clean," but it is nicer and much more powerful than Tkinter. You will also get better support, since more people use it these days.

sep332
"Much nicer" is definitely subjective. With the latest versions of Tkinter which includes the themed widgets, Tkinter looks as modern as any other cross platform toolkit.
Bryan Oakley
+1  A: 
import Tix

help(Tix.NoteBook)

If on Windows, Tix is included. On other platforms, just install the necessary package.

If on a recent enough Python (2.7) and/or Tcl/Tk (8.5) (with the optional python-ttk module), you can do:

import ttk

help(ttk.Notebook)
ΤΖΩΤΖΙΟΥ
Sadly, I get an error when I try to use the Tix.NoteBook class on my Windows box. This does look like the way to go if I ever decide to use Tkinter for anything major, but the effort of compiling everything from source would be prohibitive for a small project.
Eli Courtwright
Tell us the error and we can help with guidance.
ΤΖΩΤΖΙΟΥ
Actually I figured it out on my own; the number of Python Tix resources online is distressingly low, and I'll probably post a Stack Overflow question about that if nothing else. Thanks again for the suggestion to use Tix.
Eli Courtwright
tix is pretty old and not very well supported. The best solution going forward is ttk.Notebook. Starting with tk version 8.5 there are themed widgets (ttk) which includes a notebook.
Bryan Oakley
+1  A: 

What problems did you have with pmw? It's old, yes, but it's pure python so it should work.

Note that Tix doesn't work with py2exe, if that is an issue for you.

John Fouhy
My problem was that the setup.py script didn't work. I later installed it by simply copying the Pmw directory into site-packages. But this kind of error combined with the oldness of the package makes me reluctant to use it. At least wxPython is current, although I still like Tkinter better.
Eli Courtwright
+1  A: 

While it may not help you at the moment, tk 8.5 comes with an extended set of widgets. This extended set is available with tk 8.4 by way of an extension known as "tile". Included in the extended set of widgets is a notebook widget. Unfortunately, at this time Tkinter by default uses a fairly old version of Tk that doesn't come with these widgets.

There have been efforts to make tile available to Tkinter. Check out http://tkinter.unpythonic.net/wiki/TileWrapper. For another similar effort see http://pypi.python.org/pypi/pyttk. Also, for a taste of how these widgets look (in Ruby, Perl and Tcl) see http://www.tkdocs.com/.

Tk 8.5 is a huge improvement over stock Tk. It introduces several new widgets, native widgets, and a theming engine. Hopefully it will be available by default in Tkinter some day soon. Too bad the Python world is lagging behind other languages.

*update: The latest versions of Python now include support for the themed widgets out of the box. _*

Bryan Oakley
Sweet! I'll definitely check this out. Thanks, and I definitely agree about Python lagging behind other languages at GUI stuff; I guess the problem is that it's so often used for web programming and other server/scripting software that GUI work just isn't a priority for most developers.
Eli Courtwright