in reply to How to align the contents inside a ListboxSelect of Tk GUI

Evel:

I think the anonymous poster above meant change to a monospaced font, which will make the characters all take the same width:

iiiiiiiii

wwwwwwwww

Where a typical variable pitch font lets normally-narrow character take less horizontal space than a normally-wide character:

iiiiiiiii

wwwwwwwww

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Replies are listed 'Best First'.
Re^2: How to align the contents inside a ListboxSelect of Tk GUI
by huck (Prior) on Oct 10, 2017 at 13:12 UTC

    as an example, with Tkx i do :

    Tkx::font_configure('TkFixedFont',-size=>8); .... my $lb = $w_bfrm->new_tk__listbox( -height =>3 , -selectmode=>'extended' , -font =>'TkFixedFont' );

      I using Tk, anyway thanks for your input.
Re^2: How to align the contents inside a ListboxSelect of Tk GUI
by Evel (Acolyte) on Oct 11, 2017 at 01:56 UTC
    Thanks, I just fix it by replacing the original default font with mono font. and curiosity I also want to know what the default font style name is?

      G'day Evel,

      "... I also want to know what the default font style name is?"

      You can use the cget() method (see Tk::options) to determine the default option value of any widget.

      You can find values quickly using a one-liner, e.g.

      $ perl -E 'use Tk; say MainWindow->new->Listbox->cget("-background")' #d9d9d9

      Some option values aren't individual scalars: you may get a reference returned, e.g.

      $ perl -E 'use Tk; say MainWindow->new->Listbox->cget("-font")' Tk::Font=SCALAR(0x7f972e1bbd80)

      You can just dereference as normal. Here's two examples showing the older "${ ... }", and newer "...->$*", syntaxes. See "perlref: Postfix Dereference Syntax" if you're unfamiliar with the second one.

      $ perl -E 'use Tk; say ${ MainWindow->new->Listbox->cget("-font") }' Helvetica -12 bold $ perl -E 'use Tk; say MainWindow->new->Listbox->cget("-font")->$*' Helvetica -12 bold

      Here's another example just to show different widgets have different defaults.

      $ perl -E 'use Tk; say MainWindow->new->Text->cget("-font")->$*' Courier -12

      Also be aware that, while Tk has its own defaults, these may be altered externally (e.g. a .Xdefaults file); or from within your application by a module you've loaded (e.g. a custom widget), or by your own code (e.g. one of the "option*()" methods). See Tk::option for details.

      — Ken

        Thanks again Ken, good tips about the method of getting dereference value. Yes, so now there are more fonts I can used than before, like 'Consolas', 'Courier','Lucida Console'.(https://en.wikipedia.org/wiki/Monospaced_font)