perluser-interfacebuttontcltkx

Perl Tkx, What is the Difference Between "button" and "ttk__button"?


I have been working on a GUI using Perl Tkx, and discovered that there are two separate functions you can use to create buttons. (button and ttk__button).

So far the only difference I found is that the button function appears to center justify the text while the ttk__button function appears to left justify the text.


Example using button:

#!/usr/bin/perl

use strict;
use warnings;

use Tkx;

my $text = "Hello\nworld!\n\nThis is some text...";
my $mw = Tkx::widget->new(".");

my $b = $mw->new_button(
    -text => $text,
    -command => sub { exit; },
);
$b->g_grid;

Tkx::MainLoop()

This script will center the text:

Centered text


Example using ttk__button:

#!/usr/bin/perl

use strict;
use warnings;

use Tkx;

my $text = "Hello\nworld!\n\nThis is some text...";
my $mw = Tkx::widget->new(".");

my $b = $mw->new_ttk__button(
    -text => $text,
    -command => sub { exit; },
);
$b->g_grid;

Tkx::MainLoop()

This script will left justify the text:

Left justified text


I was wondering what other differences there are between these two functions and whether there is any particular reason there are two separate functions that create buttons. Is one of these typically better to use than the other?

Also is there any way to center justify the text using the ttk__button function?

EDIT:

I added the "Tcl" tag to this since Perl Tkx is essentially built off of Tcl. I'm pretty good with Perl but I am somewhat of a novice when it comes to Tcl.

Although it may not seem like it at first glance, this is actually more of a Tcl question than a Perl question so I would love to hear an answer from someone who is experienced with Tcl.


NOTE:

To center text in a ttk__button add the following line to your code:

Tkx::ttk__style_configure('TButton', -justify => 'center');


Solution

  • Button is one of the, let's say, 'traditional' widgets. The ttk family of widgets are more modern and are designed to pay attention to the display configuration of the Host OS. If you want your app to blend in with your user's chosen 'theme' then use the ttk widgets. On the other hand, if you like to do lots of work to fit in, or would like your application to stick out like a sore thumb, then by all means use the 'traditional' widgets.

    Finer control of ttk widgets can be exerted via the -style option. You may want to look at the tutorial page @ http://www.tkdocs.com/tutorial/styles.html .

    For what it's worth, buttons do not frequently contain multi-line text. There are other widgets that are designed with text layout in mind.

    EDIT:

    From tjwrona1992's comment: Tkx::ttk__style_configure('TButton', -justify => 'center');