Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

GUI Look & Feel in perl tk

by vr786 (Sexton)
on Nov 26, 2010 at 12:26 UTC ( [id://873853]=perlquestion: print w/replies, xml ) Need Help??

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

Hi monks, I have designed a small gui in perl tk , how can i make gui looks good there is any specific colors and can any one suggest me ......

Replies are listed 'Best First'.
Re: GUI Look & Feel in perl tk
by kcott (Archbishop) on Nov 26, 2010 at 15:00 UTC

    Before you start making any changes there's a few things you need to consider. If you're writing a GUI that is only ever going to be used by yourself and will only ever be used on one platform, then feel free to go to town with whatever colours, fonts, sizes and so on that suit your personal taste. If, as is more likely the case, you want to show (give/sell/etc.) your GUI to anybody else, then you should resist the urge to make direct changes within your code (e.g. Button(-background => '#ff0000')).

    Perl/Tk GUIs will, in general, take on the look-and-feel of the underlying system (colours, fonts, scrollbars, menus, window decorations and so on) and most users will have set that up for their own person tastes and requirements. Bear in mind that people's eyesight varies and, accordingly, they will have set up, for instance, different sized fonts, contrasting text, background and foreground colour combinations; a sizeable proportion (I think the number is around 5-10%) of the human population is colour blind to some degree, so what looks like, say, a pleasant woodland theme to you is just a blur to someone else; there's also cultural differences: what appears as a fun or happy set of colours to you could well be funereal to the next person.

    On Unix systems, you can set up one or more themes that could be added to the .Xdefaults file - you could distribute these with your GUI. There's possibly similar facilities for other systems but that's an area I'm unfamiliar with.

    For changes you wish to apply within your code, you should aim to use the Option Database - see Tk::option (and note this is different from the similarly named Tk::options). This will allow users of your GUI to override your settings with their personal preferences. As an example, I find the default borders around buttons to be somewhat chunky, so I include code like this:

    my $priority = q{startupFile}; ... $mw->optionAdd('*Button*borderWidth', 1, $priority); $mw->optionAdd('*Button*activeBorderWidth', 1, $priority);

    For fonts (see Tk::font), consider building these from components rather than specifying every attribute for every font. Here's some example code:

    my %default_style = ( -size => 10, -weight => 'normal', -slant => 'roman', -underline => 0, -overstrike => 0, ); my %serif_default_style = (-family => 'Times', %default_style); my %mono_default_style = (-family => 'Courier', %default_style); my $serif_default_font = $mw->fontCreate(%serif_default_style); my $serif_bold_font = $mw->fontCreate(%serif_default_style, -weight => + q{bold});

    By doing this, if you decide you want your default size to be 12 instead of 10, you only need to make 1 change rather than having to edit every font you've created.

    When changing window dimensions, bear in mind that screens come in many different sizes. You can use methods such as screenheight() and screenwidth() (see Tk::Widget) to set an appropriate geometry() for any screen.

    Finally, for actually selecting a default theme for your GUI, I'd suggest using whatever tool comes with your system for creating custom themes. These tools typically have some sort of change/preview facility which should be a lot easier to use than manually changing your code and then running your application to see how it looks. Remember to always change background and foreground colours in pairs - it's a common mistake to set the background to, say, black and then later find text insertion appears to be broken when, in fact, the text is fine except it still has its original black colour and is therefore invisible.

    -- Ken

Re: GUI Look & Feel in perl tk
by zentara (Archbishop) on Nov 26, 2010 at 14:04 UTC
    Tk dosn't have themes yet, like Gtk2, but you can setup default options, and you can probably design some nice color combinations.... I prefer limegreen, hot pink, and black ;-)
    #!/usr/bin/perl -w use strict; use Tk; my $mw=tkinit; $mw->optionAdd("*background"=>'lightblue','userDefault'); $mw->Listbox->pack->insert(0,qw/a listbox/); $mw->Text->pack->insert('1.0','text widget'); $mw->Entry->pack->insert(0,'entry widget'); MainLoop;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: GUI Look & Feel in perl tk
by Anonymous Monk on Nov 26, 2010 at 12:38 UTC
Re: GUI Look & Feel in perl tk
by stefbv (Curate) on Nov 26, 2010 at 14:42 UTC

    I have a nice example in my library about "an experiment for skinning Perl/Tk window", the author is Cerone Kirsle, Aug 2, 2006. I searched on the Net, and didn't find it anymore, so I think it's a good idea to post it here for reference.

    Regards, Stefan

Re: GUI Look & Feel in perl tk
by emav (Pilgrim) on Nov 27, 2010 at 13:23 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://873853]
Approved by marto
Front-paged by biohisham
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-24 16:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found