In addition to the textvariable problem which has been pointed out, what you need to do is add a -browsecmd to make your program work.
#!/usr/bin/perl use strict; use Tk; use Tk::BrowseEntry; my $AssignMet='\Input\0InputMeteo.txt'; my $AssignTmy='\Input\TMY2\FR-Trappes-71450.tm2'; my $type='Site'; my $simuTl = new MainWindow(); my $f0 = $simuTl->Frame(); my $l="Type de fichier m\xE9t\xE9o"; my $lb0 = $f0->BrowseEntry( -label => $l, -choices => ['Site','TMY2'], -variable => \$type, -browsecmd => \&detect , )->pack(); $f0->pack(); my $f1 = $simuTl->Frame(); my $l="Fichier de donn\xE9es m\xE9t\xE9o"; my $lab1 = $f1->Label( -text => $l, ); my $ent1; if ($type eq "Site") { $ent1 = $f1->Entry(-text => $AssignMet); $lab1->pack(-side => 'left'); $ent1->pack(); $f1->pack(); } else { $ent1 = $f1->Entry(-text => $AssignTmy); $lab1->pack(-side => 'left'); $ent1->pack(); $f1->pack(); } MainLoop; sub detect{ if ($type eq "Site") { $ent1-> configure (-text => $AssignMet); } else { $ent1->configure(-text => $AssignTmy); } }
As an oddity, I did find that your erroneous use of textvariable did work. This is somewhat bad programming, so I show the code here in the READMORE. Do not expect this switching of textvariable to be reliable, but somehow it works.
#!/usr/bin/perl use strict; use Tk; use Tk::BrowseEntry; my $AssignMet='\Input\0InputMeteo.txt'; my $AssignTmy='\Input\TMY2\FR-Trappes-71450.tm2'; my $type='Site'; my $simuTl = new MainWindow(); my $f0 = $simuTl->Frame(); my $l="Type de fichier m\xE9t\xE9o"; my $lb0 = $f0->BrowseEntry( -label => $l, -choices => ['Site','TMY2'], -variable => \$type, -browsecmd => \&detect , )->pack(); $f0->pack(); my $f1 = $simuTl->Frame(); my $l="Fichier de donn\xE9es m\xE9t\xE9o"; my $lab1 = $f1->Label( -text => $l, ); my $ent1; if ($type eq "Site") { $ent1 = $f1->Entry(-textvariable=>\$AssignMet); $lab1->pack(-side => 'left'); $ent1->pack(); $f1->pack(); } else { $ent1 = $f1->Entry(-textvariable=>\$AssignTmy); $lab1->pack(-side => 'left'); $ent1->pack(); $f1->pack(); } MainLoop; sub detect{ if ($type eq "Site") { $ent1-> configure (-textvariable=>\$AssignMet); } else { $ent1->configure(-textvariable=>\$AssignTmy); } }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re: perl/Tk Entry updating by zentara
in thread perl/Tk Entry updating by contact@solamen.fr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.