Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Tk Clear Text

by PilotinControl (Scribe)
on Aug 26, 2013 at 12:56 UTC ( #1050957=perlquestion: print w/ replies, xml ) Need Help??
PilotinControl has asked for the wisdom of the Perl Monks concerning the following question:

Good Morning Monks here is my question for the day. Refering to the code below once the "Add" button is pressed the data is entered into the file and the window is withdrawn and the mother window is de-iconified. If I select the "Add" button again the data entry box reappears and instead of having clear entry boxes the previous data is still shown. I've tried using : update, delete etc. What I am missing? Thanks in advance.

sub addnewcar { $addcm = $mw->Toplevel(); $addcm->transient($mw); $addcm->group($mw); $addcm->resizable(0,0); $addcm->protocol('WM_DELETE_WINDOW' => sub { print "do nothing here\n"; #prevents destruction of $addcm #by WM control }); # Create the main window $addcm->configure(-title=>'Add Car'); $addcm->geometry('285x270+0+0'); my $personInfo = $addcm->Frame()->pack(-side=>'top',-fill=>'x'); my $personLeft = $personInfo->Frame()->pack(-side=>'left',-fill=>'x' +); my $personRight = $personInfo->Frame()->pack(-side=>'left',-fill=>'x' +,-padx=>20,-pady=>20); $personLeft->Label(-text=>'Car')->pack(); $personLeft->Label(-text=>'')->pack(); $personLeft->Label(-text=>'Make')->pack(); $personLeft->Label(-text=>'Model')->pack(); $personLeft->Label(-text=>'Color')->pack(); $personLeft->Label(-text=>'Year')->pack(); $personRight->Label(-text=>'')->pack(); $personRight->Label(-text=>'')->pack(); $personRight->Entry(-width=>20,-borderwidth=>2, -relief=>'sunken',-textvariable=>\$perInfo->{MAKE})->pack(); $personRight->Entry(-width=>20,-borderwidth=>2, -relief=>'sunken',-textvariable=>\$perInfo->{MODEL})->pack(); $personRight->Entry(-width=>20,-borderwidth=>2, -relief=>'sunken',-textvariable=>\$perInfo->{COLOR})->pack(); $personRight->Entry(-width=>20,-borderwidth=>2, -relief=>'sunken',-textvariable=>\$perInfo->{YEAR})->pack(); my $saveFrame = $addcm->Frame()->pack(-side=>'top',-fill=>'x'); $saveFrame->Button(-text => 'Add Car', -command => sub { &addcar(); sl +eep 2; $addcm->withdraw; $rm->deiconify;} )->grid(-row, 2, -column, 0, -sticky => 'nesw'); $balloon->attach($saveFrame, -balloonmsg => "Return To Add Car"); sub addcar { open(OUT,">>cardata.txt"); print OUT $perInfo->{MAKE} . ":"; print OUT $perInfo->{MODEL} . ":"; print OUT $perInfo->{COLOR} . ":"; print OUT $perInfo->{YEAR} . "\n"; close(OUT); } } # END ADD NEW CAR

Comment on Tk Clear Text
Download Code
Re: Tk Clear Text
by choroba (Abbot) on Aug 26, 2013 at 13:01 UTC
    The code you posted cannot be run to demostrate the problems you mentioned. So, only a wild guess is possible: Do you clear the textvariable as well? Maybe its scope is a bit too broad (maybe even global?).
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Tk Clear Text
by hdb (Parson) on Aug 26, 2013 at 13:06 UTC

    You seem to store the data in the variable $perInfo which seems to be declared globally, so you need to delete the contents before re-creating the window.



      Fixed! Thanks it was defined globally...once defined within the sub the entry boxes cleared.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1050957]
Approved by hdb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (16)
As of 2014-07-28 20:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (207 votes), past polls