3

What are the disadvantages of the Tk module compared to other solutions to create a GUI in Perl?

brian d foy
  • 129,424
  • 31
  • 207
  • 592
sid_com
  • 24,137
  • 26
  • 96
  • 187
  • Why do you only care about disadvantages? And relative to what? See also http://stackoverflow.com/questions/1249186/should-i-use-perl-tk-tcltk-or-tkx-for-a-perl-gui – Michael Carman Apr 07 '10 at 14:57
  • I hoped somebody would argue me out of doing perl-gui-programming. – sid_com Apr 07 '10 at 16:44

2 Answers2

12

I toured the various gui modules for Perl recently, and here is my summary (disclaimer: ultimately I found that none of the existing modules met my needs so I started writing my own gui toolkit).

Tk - Decent to work with and the interface is very perlish. The gui itself is a bit dated looking, and doesnt take advantage of any of the operating system's native widgets (like filepickers). On most systems it will require a C compiler to install.

Wx - Difficult to work with, un-perlish interface. Large programs almost require a gui builder to keep track of everything. Support for os level widgets is mixed. Nicer looking than Tk IMO. Compilation is involved, requires installing several libraries, can be difficult to get running on windows. The assembly of programs is very procedural, and does not map cleanly to what the program will actually look like.

Qt - last I looked this module was more or less abandoned and only supports Qt3. I didn't try to install it, but i imagine it needs a compiler.

Prima - Similar to Tk it has a dated appearance. Requires a compiler.

W32::GUI - I ruled this out early since it is not cross platform.

XUL::Node / POE::XUL::Node - rather heavy dependency tree that includes C code. Seems unmaintained and I had mixed experiences getting it to install. Windows was a no go, OSX was a no go, it had limited functionality on OpenSUSE. It also only supports a subset of the XUL language.

I found that none of the existing gui toolkits made it easy enough to distribute your application to end users. It is ok to expect programmers to jump through the hoops of resolving library dependencies and compiling code, but end users aren't going to do that. So the first requirement I had was to be pure Perl.

Secondly, nearly all of the existing gui toolkits force you to work in a very procedural manner: Create a container. Create a packer for the container. Create an object. Set properties on that object. Add the object to the packer. Run the packer to fill the container object. Repeat.

Instead, I find that nested design (like HTML) is easier to follow for two reasons. First off, since objects are nested, there is no need to name everything (label_456, label_457...). Secondly, the structure of the program mirrors the structure of what is displayed.

So I started work on XUL::Gui, and its been coming along rather well. It is pure Perl, and only depends on core modules for ease of installation. It has one external requirement, which is that a recent (3+) copy of Firefox is installed. It uses the familiar design pattern of web development with nested tags styled with CSS. It is certainly at a level where you could write fully featured single window applications with it.

Hopefully this helps you to figure out which toolkit is best for your project.

Eric Strom
  • 39,821
  • 2
  • 80
  • 152
  • You can get wxPerl installed on Windows without complication by using the binaries mentioned here http://www.wxperl.it/p/download.html – Matthew Lock May 03 '17 at 03:10
2

Tk has not been developed in a very long time. ActiveState now recommends development with their Tkx toolkit, which provides a thin layer over TclTk. It means that themed widgets are possible. But, TclTk is still quite primitive compared with many other GUI toolkits.

I haven't tried XUL:Gui but it seems the way to go.

LozzerJP
  • 856
  • 1
  • 8
  • 23
  • 1
    Tk (especially with the Ttk widgets) looks very good indeed on Windows and OSX, where native widgets are used. We've been studying how to use "native" widgets on Linux too, but the problem is (apparently, according to a recent conference paper by Georgios Petasis) that there are some rather pervasive issues with metrics GTK and Qt themes, even in common ones. – Donal Fellows Jan 11 '11 at 13:36
  • And I said "native" because Tk *is* a native X11 toolkit, and always has been since well before either GTK or Qt were created. – Donal Fellows Jan 11 '11 at 13:40
  • Tk might not get much development these days, but at least it's kept alive and will still install on most systems with most perl versions. – Slaven Rezic Jul 17 '13 at 13:40
  • @DonalFellows: The accepted answer says "The gui itself is a bit dated looking, and doesnt take advantage of any of the operating system's native widgets (like filepickers)". Are both those defects gone now on Windows? Also, since you said Tk looks very good on Windows, I tried to find a screenshot using Google Images, but that came up only with the old ugly interface, could you provide a link if possible? – Sundar R Jul 23 '13 at 12:06
  • I still have a few apps that I develop with Tkx, and the results can be impressive on all platforms with a native look even on Linux (and I don't mean X11). But, things like drag and drop, graphical interface builders etc, are not available. I now do this kind of development in Python with PyQt. This approach has problems building on OS X, but the results are very pretty. – LozzerJP Jun 17 '14 at 13:27