Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^3: Insert checkbutton into MListbox

by chessgui (Scribe)
on Feb 06, 2012 at 10:49 UTC ( #952051=note: print w/replies, xml ) Need Help??

in reply to Re^2: Insert checkbutton into MListbox
in thread Insert checkbutton into MListbox

Forget list widgets. Use a Text widget. Pack all the buttons in it that you need. Even add buttons to move items up and down the list (in each row you would have a Checkbutton, an 'UP' Button and a 'DOWN' Button. When the user chooses to move an element a row up or down just create the Text widget from scratch again with the Buttons in the new order and redisplay it.

Replies are listed 'Best First'.
Re^4: Insert checkbutton into MListbox
by ghosh123 (Monk) on Feb 06, 2012 at 11:18 UTC

    Can you please explain the answer a bit more. "Pack all the buttons in it" ... here button means checkbutton ...right ? And you want me to create a 'up' and 'down' button beside each of those checkbuttons in each row ? Currently I am running the following code. If you just look at it,it will help you to explain me a bit elaborately

    #!/usr/bin/perl use strict; use warnings; use Tk; use Tk::TList; use Tk::ItemStyle; my $mw = MainWindow->new(); my $style = $mw->ItemStyle('window'); my $tl = $mw->Scrolled("TList", -scrollbars => "osoe")->pack(-side=>'l +eft', -fill => 'y'); $mw->Button(-text => "UP", -command => \&press_func_up)->pack(); $mw->Button(-text => "DOWN", -command => \&press_func_dwn)->pack(); foreach my $item ("State" , "Dependency", "CalcTime", "Result") { my $btn = $tl->Checkbutton(-text => $item); $tl->insert('end', -itemtype => 'window', -style => $style, -widge +t => $btn); } sub press_func_up { # Move items up } sub press_func_dwn { # Move items up } MainLoop;
      use Tk; my $mw=new MainWindow; my $item_width=15; my %attr_item=('-background'=>'#ffafaf'); my %attr_btn=('-background'=>'#afffaf','-activebackground'=>'#7aaa7a') +; my $text=$mw->Scrolled('Text', -insertontime=>0, -scrollbars=>'e', -width=>($item_width+15), -background=>'#efefef' )->pack; my $first=1; $text->tagConfigure('item',%attr_item); foreach my $item ("State" , "Dependency", "CalcTime", "Result") { my $btn=$text->Checkbutton(%attr_item,'-activebackground'=>'#ff7f7 +f'); my $up=$text->Button(-text=>'Up',%attr_btn); my $down=$text->Button(-text=>'Down',%attr_btn); $text->insert('1.0',"\n") unless $first; $first=0; $text->windowCreate('1.0',-window=>$up); $text->windowCreate('1.0',-window=>$down); $text->windowCreate('1.0',-window=>$btn); $text->insert('1.0',sprintf('%-'.$item_width.'s',$item)); $text->tagAdd('item','1.0',"1.$item_width"); } MainLoop;

        This was really helpful. I was also thinking of using hash for storing and re-positioning the text items upon clicking on up and down button. I proceeded as below but a bit stuck. Let us assume I have put your code in a subroutine called build_layout()

        my $dynamic_hash = {0 => "job",1=> "state",2 =>"dependencies",3=>"resu +lt"}; &build_layout($init_hash); sub build_layout { ## samething what u have sent foreach my $itemkey (sort keys %$dynamic_hash) { my $btn=$text->Checkbutton(%attr_item,'-activebackground'=>'#ff7f7 +f' ); my $up=$text->Button(-text=>'Up',%attr_btn, -command => [\&moveup, +${$dynamic_hash}{$itemkey} ); my $down=$text->Button(-text=>'Down',%attr_btn,)-command => [\&mov +edown,${$dynamic_hash}{$itemkey}; ..... ..... $text->insert('1.0',sprintf('%-'.$item_width.'s',${$dynamic_hash}{ +$itemkey})); } sub moveup { my $text = shift ### not able to proceed here } sub movedown { }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://952051]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2018-03-22 00:45 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (272 votes). Check out past polls.