perluser-interfacetkx

Perl Tkx examples or tutorials


I been trying to create Perl GUI using Tkx but I'm having trouble with a couple of issues.

i have been looking at these sites:

http://rainbow.ldeo.columbia.edu/documentation/tkperl/

http://docs.activestate.com/activetcl/8.5/tcl/tk_contents.htm

http://www.tkdocs.com/tutorial/onepage.html

But the problem is that the examples do not seem to be working for me.

I want to use an Object oriented approach as much as possible, but without using moose(for now) so i can get my head around how objects work in Perl.

Edit: link to a good oo tutorial

So I can already create a window:

sub main
{
    my $mainWindow = Tkx::widget->new(".");
    $mainWindow->g_wm_title("FixViewer");
    $mainWindow->g_wm_minsize(400,500);

    Tkx::MainLoop();
}

How do I create a frame and put a Gridlayout on it?

Would someone be able to show me how, or link me to a good tutorial.

Thanks

Update:

use strict;
use warnings;
use Tkx;

sub main
{
    my $mainWindow = Tkx::widget->new(".");
    $mainWindow->g_wm_title("FixViewer");
    $mainWindow->g_wm_minsize(100,100);

    my $contentFrame = $mainWindow->new_ttk__frame(-padding => "3 3 12 12");
    $contentFrame->g_grid(-column => 0, -row => 0, -sticky => "nwes");
    $mainWindow->g_grid_columnconfigure(0, -weight => 1);
    $mainWindow->g_grid_rowconfigure(0, -weight => 1);

    my $input;
    my $output;

    #create a textbox where user can enter input
    my $inputbox = $contentFrame->new_ttk__entry(-width => 7, -textvariable => \$input);
    $inputbox->g_grid(-column => 1, -row => 1, -sticky => "we");

    #create a lable which shows whatever is input in the input box
    my $inputlabel = $contentFrame->new_ttk__label(-textvariable => \$output);
    $inputlabel->g_grid(-column => 1, -row => 2, -sticky => "we");

    #create a button and bind a sub to it
    my $button = $contentFrame->new_ttk__button(-text=> "Click me",-command=> sub {dostuff(\$output,\$input);} );
    $button->g_grid(-column => 1, -row => 3, -sticky => "w");

    #bind return key to method, so method will get called when key is hit
    $mainWindow->g_bind("<Return>",sub {dostuff(\$output,\$input);});

    Tkx::MainLoop;
}

sub dostuff
{
    my $output = shift;
    my $input = shift;
    $$output = $$input;
}

#############
# Call main #
&main();
#############

I managed to kinda figure some stuff out. More examples or links to tutorials are still very welcome


Solution

  •  my $contentFrame = $mainWindow->new_ttk__frame(-padding => "3 3 12 12");
        $contentFrame->g_grid(-column => 0, -row => 0, -sticky => "nwes");
        $mainWindow->g_grid_columnconfigure(0, -weight => 1);
        $mainWindow->g_grid_rowconfigure(0, -weight => 1);