Perl Tkx, what is the difference between "button" and "ttk__button"?

I am working on a GUI using Perl Tkx and found that there are two separate functions that can be used to create buttons. ( button and ttk__button ).

Until now, the only difference I found is that the function button seems that center aligns the text, while the function ttk__button is left to 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 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 leave text alignment:

Left justified text


I was wondering what other differences exist between the two functions and if there is any specific reason, there are two separate functions that the buttons create. Is one usually better to use than the other?

ttk__button there also a way to align text with the ttk__button function?

EDIT:

I added the "Tcl" tag to this, since Perl Tkx is essentially built from Tcl. I am very familiar with Perl, but I start a little when it comes to Tcl.

Although this may not seem like this at first glance, it is actually a Tcl question rather than a Perl question, so I would like to hear the answer from someone who is testing Tcl.


Note:

In the center of the text in ttk__button add the following line to your code:

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

+5
source share
2 answers

Button is one of, say, "traditional" widgets. The ttk widget ttk more modern and is designed to pay attention to the display configuration of the host operating system. If you want your application to blend in with the theme of your choice, use ttk widgets. On the other hand, if you like to do a lot of work to fit or would like your application to stick out like a sore thumb, then, in any case, use the "traditional" widgets.

More precise control over ttk widgets can be done with the -style option. You can see the manual page @ http://www.tkdocs.com/tutorial/styles.html .

For what it's worth, buttons often don't contain multi-line text. There are other widgets that are tailored to the text.

EDIT:

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

+5
source

Tk has two classes of widgets: traditional and piled . Traditional widgets are the ones that have been around since the creation of Tk. Tiled widgets are relatively new. They emulate their own widgets by supporting themes. Many (but not all) widgets are available in both forms. The tile began as a separate library before being integrated into Tk 8.5 as Ttk .

Unfortunately, switching from traditional to tiled widgets by Tk is not as simple as adding the “use ttk” operator, because traditional and twisted widgets do not necessarily have the same set of configuration parameters.

In Tkx, the ttk prefix ttk used to indicate the tile version of the widget. The Tcl Tk wiki has a comparison of ttk widgets using different themes. (The "classic" theme matches the look of traditional Tk.) Here, both button and ttk__button rendered on my system (Win7):

button vs ttk button

Traditional widgets are more flexible. You can customize additional attributes and do this based on each widget. Tiled widgets look better (i.e. Native) and make it easy to change the overall look of your application.

Personally, I always use ttk widgets when they are available.

+2
source

Source: https://habr.com/ru/post/1210925/


All Articles