Perl TKx

Tutorial link:  http://www.tkdocs.com/tutorial

 

Widgets:

Frame:

$frame = $parent->new_ttk__frame;

Padding:
$frame->configure(-padding => "5 10")

Borders:

$frame->configure(-borderwidth => 2, -relief => "sunken")

Label:
$label = $parent->new_ttk__label(-text => "Full name:");

Display Text:
$label->configure(-textvariable => \$resultContents);
$resultContents = "New value to display";

Display Image:
Tkx::image_create_photo( "imgobj", -file => "myimage.gif");
$label->configure(-image => "imgobj");

Layout:
"e", "se", "s", "sw", "w", "nw" or "center".

Specifying two opposite edges, such as "we" (west, east) means that the widget will be stretched, in this case so it is stuck both to the left and right edge. 

If you want the widget to expand to fill up the entire cell, grid it with a sticky value of "nsew"

Button:
$button = $parent->new_ttk__button(-text => "Okay", -command => sub {submitForm();});
Set the option to "active" to specify this is a default button; the regular state is "normal".

$button->state("disabled")                  ;# set the disabled flag, disabling the button
$button->state("!disabled")                 ;# clear the disabled flag
$button->instate("disabled")                ;# return 1 if the button is disabled, else 0
$button->instate("!disabled")               ;# return 1 if the button is not disabled, else 0
$button->instate("!disabled", sub {mycmd})  ;# execute 'mycmd' if the button is not disabled

Check Button:
$check = $parent->new_ttk__checkbutton(-text => "Use Metric", -command => sub {metricChanged},
	    -variable => \$measuresystem, -onvalue => "metric", -offvalue => "imperial")

Radio Button:

$home = $parent->new_ttk__radiobutton(-text => "Home", -variable => \$phone, -value => "home");
$office = $parent->new_ttk__radiobutton(-text => "Office", -variable => \$phone, -value => "office");
$cell = $parent->new_ttk__radiobutton(-text => "Mobile", -variable => \$phone, -value => "cell");

Entry/text input box:

$name = $parent->new_ttk__entry(-textvariable => \$username)

Entry/text input, change current value:
print "current value is " . $name->get
$name->delete(0, "end")         ; # delete between two indices, 0-based
$name->insert(0, "your name")   ; # insert new text at a given index

Combo Box:
$country = $parent->new_ttk__combobox(-textvariable => \$countryvar)
Use get and set to change current value.  To bind select event:
$country->g_bind("<<ComboboxSelected>>", sub { script })

To predefine values:
$country->configure(-values => "USA Canada Australia")

Grid:

Every column and row has a "weight" grid option associated with it, which tells it how much it should grow if there is extra room in the master to fill. By default, the weight of each column or row is 0, meaning don’t expand to fill space.

For the user interface to resize then, we’ll need to give a positive weight to the columns we’d like to expand. This is done using the "columnconfigure" and "rowconfigure" methods of grid. If two columns have the same weight, they’ll expand at the same rate; if one has a weight of 1, another of 3, the latter one will expand three pixels for every one pixel added to the first.

reference link: http://www.tcl.tk/man/tcl8.5/TkCmd/grid.htm

Example:

$frame->g_grid(-column => 0, -row => 0, -columnspan => 3, -rowspan => 2);
$namelbl->g_grid(-column => 3, -row => 0, -columnspan => 2);

 

List Box:

$parent->new_tk__listbox(-height => 10)

Example:
$cnames = ''; foreach $i (@countrynames) {$cnames = $cnames . ' {' . $i . '}';};
$lbox = $content->new_tk__listbox(-listvariable => \$cnames, -height => 5);

ScrollBar:
$s = $parent->new_ttk__scrollbar(-orient => 'vertical', -command => [$listbox, 'yview']);
$listbox->configure(-scrollcommand => [$s, 'set']);