Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Tk Clear Text

by PilotinControl (Monk)
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

Replies are listed 'Best First'.
Re: Tk Clear Text
by hdb (Monsignor) 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.

Re: Tk Clear Text
by choroba (Bishop) 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?).
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1050957]
Approved by hdb
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2018-01-19 01:45 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (215 votes). Check out past polls.