Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

How do you make Tk look good?

by Limbic~Region (Chancellor)
on Jul 15, 2008 at 20:01 UTC ( #697789=perlquestion: print w/replies, xml ) Need Help??
Limbic~Region has asked for the wisdom of the Perl Monks concerning the following question:

After about 4 years, I have finally crossed "learn Tk" off my to-do list. I was commenting in freenode's #perl that it looked horrible and I would be moving to another framework when Khisanth asked why don't I use one of the Win32 themes using Tile widgets. The screen shots were impressive, so I figured I would give it a try.

I contacted the author of Tk and received a quick reply that Tile support is scheduled for the next release but that there was no timetable for that. I searched a bit and read something where Tkx provided access to more Tk/tcl stuff and I decided to give it a try. Once I read through the tutorial and the glaze on my eyes wore off, I emailed the author. Though I received a timely response, miscommunication on my part didn't result in the answer I was hoping for.

I pressed on without the first clue what I was doing and came up with the following:

#!/usr/bin/perl use strict; use warnings; use Tkx; Tkx::package_require('tile'); Tkx::tile__setTheme('xpnative'); my $mw = Tkx::widget->new("."); $mw->new_ttk__button( -text => 'Hello, world', -command => sub { $mw->g_destroy; }, )->g_pack; Tkx::MainLoop();

Yay! It works and looks good on Win32. Unfortunately, it seems like almost none of the knowledge I gained while learning Tk is transferrable to Tkx.

Does anyone have any hints on making Tk on Win32 both easy and pretty? I plan on learning other cross-platform frameworks such as Wx in the future so suggesting them here is not useful (to me).

Cheers - L~R

Replies are listed 'Best First'.
Re: How do you make Tk look good?
by samtregar (Abbot) on Jul 15, 2008 at 22:51 UTC
    If you like how Tile looks but can't deal with the TCLishness of Tkx, why not add support for it to the Tk module? Shouldn't be too hard, I'd imagine, although I haven't looked at how Tile works.

    If you want a better answer you'll need to be more specific about what you're looking for. I also happen to think Tk looks like crap but I be our definitions of "pretty" aren't the same.


      I may be completely wrong, but AFAIK, the Tk module is more or less independent from the main tcl/tk development effort. Which makes things more difficult to port than they maybe should be.

      There's also Tcl::Tk, which - like Tkx - uses Tcl to interface with the Tk GUI. Which also supports Tiles, and also suffers from more or less the same incompatibilities as Tkx.

      When I emailed the author of Tk, I asked if there was ANY way to get Tile support. I would have thought if it wasn't too hard to add the support, I would have been given a pointer and heard "patches welcome". I think it is beyond my capabilities.

      Cheers - L~R

        Unless you're a serious XS/C hacker, you'll likely get lost amid the low level stuff in Tk.

        As joost mentioned, you might try Tcl::Tk. vkon claims its pretty compatible, but I haven't tried it yet, due to a memo1 I got circa 2006.

        1. "If it doesn't run in a browser it don't mean sh*t.". You might check your email archives to see if you got the memo too.

        Perl Contrarian & SQL fanboy
        So, what did he say? If he just didn't respond I don't think you can draw any conclusions about how hard it is. (UPDATE: whoops, I see now that you had this in your original post!)

        I don't see how you can give up on something you obviously want quite badly without even trying... You might learn something even if you're ultimately not successful. Since the author is already planning to integrate Tile in the future you could ask him how he plans to do it.


Re: How do you make Tk look good?
by zentara (Archbishop) on Jul 16, 2008 at 12:48 UTC
    I'm one of those types that like to get one thing working well and under my control, and use that come what may. That said, I decided a long time ago, that the Canvas (and Tk::Zinc) widgets, will do anything you want, and can be made to look as nice as the effort you are willing to put into it. Just look at the Tk::Zinc demo. Now that the Goo::Canvas is coming along nicely( for Gtk2), I will probably concentrate on that.

    If you try, you will find that emulating the regular widgets in Tk on a Canvas, is not that difficult. You get far more control over all the bindings (which is a real hassle on some of the regular widgets, where button 1 presses are predefined), and you can make nice shapes and graphics for buttons and labels. The biggest problem you need to deal with is the size and spacing of text. I found an easy workaround by taking the bbox of a capital W, and use that as the default spacing for the font used. Using that, you can make side-by-side lists, and do easy drag-and-drop. Additionally, the canvas is very good at memory management on it's items......and this avoids many memory gain problems encountered in standard widgets, when you do alot of changes.

    Anyways..... if I want something to look good, I will go with one of the various canvases, not that Tkx isn't good, but I would rather be good at the canvas( where I'm in full control), than half-ass good at Tkx (where I'm dependent on some other programmers and have less control).

    Oh yeah, the canvas's already do tiling of backgrounds. :-)

    I'm not really a human, but I play one on earth CandyGram for Mongo

      If you were starting a project today from scratch and could choose either, would you go with Tk/Tk::Zinc or Gtk2?

        I would go with the Goo::Canvas, because it does everything Zinc does, (transparency, rotations, zooming, etc) plus it outputs it's entire scrollregion as pdf or svg. Zinc has no pdf output. The Tk::Canvas doesn't do transparency nor rotations(easily). So it really depends on whether I need transparency, rotations, and saving. If so.... Goo::Canvas; but if not, probably Tk::Canvas since it is more portable as of now, but in general, I don't care about MSWindows, I write for linux/unix type systems.

        I'm not really a human, but I play one on earth CandyGram for Mongo
      zentara I also used the bbox of Capital-W method, but just recently uncovered something called fontMeasure from Mastering Perl/Tk in Chapter 3 - Font Manipulation Methods. I've not really tried it yet, but would this be a better solution for this problem?
        Hi, I think I went with bbox for the Canvas, because it gives BOTH height and width. The fontMeasure says it measures width, and seems to be oriented towards text widgets, that do vertical spacing automatically for you. When you are putting lists on a Canvas, you need to take care of the vertical spacing yourself. I chose the W, since it seemed the biggest( not in honor of George W. Bush:-) ). That way, I can do one calculation for my vertical spacing (assuming font is constant)..... get the bbox of W, take the diff of the y's....add 2 pixels for line spacing.

        I'm not really a human, but I play one on earth CandyGram for Mongo

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://697789]
Approved by Old_Gray_Bear
Front-paged by Old_Gray_Bear
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2017-01-21 09:28 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (183 votes). Check out past polls.