Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Tk question: Dynamically disable radiobutton choices

by chafelix (Acolyte)
on Jul 18, 2018 at 12:32 UTC ( [id://1218747]=perlquestion: print w/replies, xml ) Need Help??

chafelix has asked for the wisdom of the Perl Monks concerning the following question:

I am creating a dialog for comparing two files. For matching purposes, the user needs to tell the program how to handle fields (for instance excel columns). Thus, the interface needs to a) specify that column i in file A corresponds to column j in file B and b) whether these matching columns are First name, last name or neither. This is important because an exact match will be performed for last name, but a first digit match will be performed on first name, e.g. 'Tim' vs. 'Timothy' should be a match. So I am adding a radiobutton for each column with the choices 'First, last and no name'. The trick is that once there is only one 'First name' and 'last name' column, so once the user has specified that this is a first name, this option should not be available to other columns.

Apart from this, which I am not sure how to do there seem to be 2 more issues with the code below: First, the Radiobutton part seems to give a strange message Second, the Browseentry appears to be filled in the box instead of the expanding list

use Tk; use Tk::BrowseEntry; my $top=MainWindow->new(); $top->title("Match Specifications"); my @names=('Last Name','First Name','Not a name'); my $value=2; #no name is default my $indicator=0;#start looping over names, indicator=0=>Last, 1=>first +, 2=>no name %main::A={1=>['Tim','Doe','other_info1'], 2=>['Mick','Lu','other_info_2']}; %main::B={1=>['Timothy','Doe','other_info1','moreinfo1'], 2=>['Michail','Lu','other_info_2','moreinfo2']}; $main::headers[0]=['F','L','O']; $main::headers[1]=['M','J','P','JJ']; my $fr=$top->Frame(-relief=>'sunken')->pack(-anchor=>'nw',-fill=>'both +'); my $counter0=0; my @selector; my $col=0;my $colshow=0; my @keys00=sort keys %main::A;my @keys0=(); push @keys0,$keys00[0]; push @keys0,$keys00[1]; my @keys200=sort keys %main::B; my @keys20=(); push @keys20,$keys200[0]; push @keys20,$keys200[1]; my $row1=0; foreach my $el(@{$main::headers[0]}){ my $row=0; $selector[$col]=$fr->Scrolled('BrowseEntry',-label=>$el,-variable=>\$ +main::matchhash{$col}, -browsecmd=>[\&show,$el,\@headers2,\@keys200]); my $h2cnt=0 ; my $h2cntall=0; ##### this is the part that must be repopulated dynamically foreach my $el2(@{$main::headers[1]}){ $selector[$col]->insert("end", $el2); $h2cnt++; $h2cntall++;}#foreach el2 $selector[$col]->grid(-row=>$row,-column=>$colshow); #### end of part to repopulate dynamically $row++; #row nonzero $fr->Label(-text=>$main::A{$keys0[0]}->[$col])->grid(-row=>$row,-colum +n=>$colshow);$row++; $fr->Label(-text=>$main::A{$keys0[1]}->[$col])->grid(-row=>$row,-colum +n=>$colshow);$row++; foreach my $name(@names){ $fr->RadioButton( -text=>$name,-variable=>\$indicator,-value=>$value) +->grid(-row=>$row, -column=>$colshow); $row++;} $colshow++; $row1=$row; $col++;}#foreach el ####### $fr->Button(-text=>'Run',-bg=> 'firebrick1' ,-command=>sub{ } ) +->grid(-row=>$row1,-column=>1); &MainLoop(); sub show{my $el=shift; my $rheaders=shift; my $rkeys=shift; }

Replies are listed 'Best First'.
Re: Tk question: Dynamically disable radiobutton choices
by zentara (Cardinal) on Jul 18, 2018 at 13:02 UTC
    First, make sure your code runs. Yours has an error, so always copy'n'paste a working example.
    $fr->RadioButton( SHOULD BE $fr->Radiobutton(
    also you should have
    use warnings; use strict;
    which would give you errors like this:
    "my" variable %main::A can't be in a package at ./1218747.pl line 14, +near "my %main::A" Global symbol "@headers2" requires explicit package name (did you forg +et to declare "my @headers2"?) at ./1218747.pl line 37.
    Your code is hopelessly broken by you trying to setup a bizarre data structure. Where did you get the syntax for %main::A?

    Here are a few simple examples of manipulating BrowseEntry widgets. You can modify the @arrays to achieve your limiting of choices. Look at the BrowseEntry widget's browsecmd. Like -browsecmd => \&do_whatever to my selections. You probably don't even need radio buttons.


    I'm not really a human, but I play one on earth. ..... an animated JAPH

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1218747]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2025-12-13 11:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (93 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.