critter has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks,

I'm still a bit in doubt on which GUI modules to use. Currently I'm looking at Tk which is well documented and easy to use on both win32 and Linux without any hassle. I wrote my first simple application in Tk which I enjoyed doing. Accept I could not get the look to match the rest of the OS.

Can Tk be themed for example like WinXp, Gnome, KDE etc?

Cheers,

Critter: A domestic animal or a non-predatory wild animal.

Replies are listed 'Best First'.
Re: Perl Tk themes
by zentara (Cardinal) on Oct 13, 2005 at 16:41 UTC
    In Tk, you have to do it manually. You could setup some .tkoptionrc file and put a bunch of defaults into it. Gtk-perl does this with .gtkrc-2.0. But with Tk, you will have to manually bring in the options and apply them, it's alot more trouble than it's worth.

    I'm not really a human, but I play one on earth. flash japh
Re: Perl Tk themes
by rcseege (Pilgrim) on Oct 13, 2005 at 17:08 UTC

    I suppose it all depends on the level of control and portability that you are looking to achieve. For example, you can create your own custom buttons in a similar manner to custom HTML buttons (using Labels, Images, and custom bindings).

    Perl/Tk does supports themes -- in a way, but not a very useful way if you're looking for portability between X and Win32, and the support that is there is slightly clunky IMO, and probably not what you are looking for.

    Probably the best support available for Tk themes currently exists through the most recent builds of Tcl/Tk and the Tcl::Tk bridge available in CPAN. It offers certain trade-offs for development. On the plus side, you have access to all the latest and greatest that the Tcl/Tk community has to offer - new features, bug fixes, other Tcl/Tk custom widgets, etc. The basic API is also very similiar to Perl/Tk's. On the minus side you have to maintain a separate Tcl/Tk distro, which adds to deployment concerns, also Tcl/Tk and Perl/Tk are not completely compatible. Subclassing is distinctly different from Perl/Tk, so that means that most custom Perl/Tk widgets are not able to be used. Tcl/Tk knowledge is not absolutely required for Tcl::Tk, but can be helpful. There are other tradeoffs as well, but this post isn't intended to be exhaustive comparison between the two.

    Rob
Re: Perl Tk themes
by Perl Mouse (Chaplain) on Oct 13, 2005 at 16:32 UTC
    Yes, it can, but I'm not sure if you really want to. You can configure the appearance of widgets using the options database (that is, under X Windows. I've no idea what the equivalent is under Microsoft Windows). I think Mastering Perl/Tk and/or Learning Perl/Tk discusses this.

    I once tried this for a tiny program, just as a proof of concept. It took a lot of hassle but it worked. And I decided to never ever repeat that experience again.

    Perl --((8:>*
Re: Perl Tk themes
by rcseege (Pilgrim) on Oct 14, 2005 at 19:19 UTC

    I reread my post and realized that I didn't really give much in the way of specifics for Perl/Tk "theme" support. As the others mentioned, themes are somewhat supported by using Widget options and the option database. This basically allows someone to specify a different set of default configuration options for widgets in an application. The key benefit here is that it's a fairly simple mechanism that can be easily reused.

    The amount of change is limited to what options a widget supports, the platform, and in the case of custom widgets, how the other coded and documented support for options. Generally these options don't allow fancy changes such as changes to the basic shape, or UI layout. For these sorts of changes (ie. circular Buttons) custom code and Images are used. As for platform-specific changes: For X, Tk support the various Tile options (-activetile, -disabledtile, -tile, -troughtile), but these do not work on Windows systems that I've used. Even some relatively basic options for some components are not portable such as the colors for Scrollbar widgets (works for X, but not Windows).

    Often, Tk apps that feature "themes" implement it in a way that is application specific which may or may not use the option database and/or custom widgets. All that I've seen require custom code. Also, to be clear - there's a difference between trying to create a specific look-and-feel, and creating support for themes. As an example, Steve Lidie created a Tk app that emulates the iTunes interface (and the aqua look-and-feel) in Chapter 15 of Mastering Perl/Tk. This is the case of an app that attempts to emulate a specific style or theme. For an example of an application that features user-modifiable theme support, take a look at Martin's File Manager (Mafima)

    If theme support is essential, your theming requirements are complex, and you don't want to spend time assembling the support yourself, I would suggest either Perl/GTk or Perl/Qt.

    Hope that helps...

    Rob