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

Hiya, i have a text box created in perl... as such...

my $txtUser = $profileOpt->Text()->pack;

and i am trying to get it to have a word in it when loaded (say the word "cheese" just for an example! However all the perldoc example dont work, and my program spits up error messages and stop executing!

Anybody hold any solutions ?

Thanks!
  • Comment on Predefining a word in a TK Entry/Text box?

Replies are listed 'Best First'.
Re: Predefining a word in a TK Entry/Text box?
by b10m (Vicar) on Mar 07, 2004 at 13:55 UTC

    Tk can be a bit tricky and confusing when you first start messing with it, but of course, you can add text to Text and Entry widgets. Please note that you're talking about two different sorts of widgets. Example:

    # If you're using the Text widget my $txtUser = $profileOpt->Text()->pack; $txtUser->insert("end", "cheese"); # If you're using the Entry widget my $txtUser = $profileOpt->Entry()->pack; $txtUser->configure(-text=>"cheese"); # Or my $txtUser = $profileOpt->Entry(-text=>"cheese")->pack;

    That should do the trick, but please, next time provide us with a little more information, like what error message do you actually get? What have you tried so far? Etc.

    HTH

    --
    b10m

    All code is usually tested, but rarely trusted.
      In an Entry you can also use -textvariable:
      my $var = "cheese"; ... my $txtUser = $profileOpt->Entry(-textvariable=>\$var)->pack;
Re: Predefining a word in a TK Entry/Text box?
by matija (Priest) on Mar 07, 2004 at 13:49 UTC
    Well, you could insert it just after you create the text box, but before you display it:
    my $txtUser = $profileOpt->Text()->pack; $txtUser->insert('end','cheese');
Re: Predefining a word in a TK Entry/Text box?
by zentara (Cardinal) on Mar 07, 2004 at 14:26 UTC
    In addition to what has already been said, you will probably want to delete what's already in the boxes, before you add your word.(or maybe not.... :-) )
    #for an entry widget $entry->delete(0,'end'); $entry->insert(0,$word);
    #for a textbox $text->delete("1.0","end"); $text->insert('end',$word); $text->see('end');

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