PilotinControl has asked for the wisdom of the Perl Monks concerning the following question:
Good Evening Monks!
I have 2 Perl Tk buttons side by side one labeled Left and one Labeled Right and each time one is pressed its text label is incremented by 10s all the way to 100. When you press the opposite button the count on the opposite button is reset to 0. Once you press that button again it starts counting where it left off when it should be reset to 0 to start counting by 10s again. My snippet of code is posted below. I will only post the sub routines responsible for counting...not the Tk code for the buttons since that should be understood.
sub leftthrottle { $button33 = $rows[$rzero]->Button(-text=>'L-FWD', -width => '3', -he +ight => "$h")->pack(-expand => 1, -fill => 'both', -padx => 2, -pad +y => 2, -side => 'left', -ipadx => 5, -ipady => 5); $button33->configure(-background => "gray", -foreground => "black"); $balloon->attach($button33, -balloonmsg => "Left Forward Speed"); $button33->bind('<ButtonPress>', \&leftfwdspeedone); $button34 = $rows[$rzero]->Button(-text=>'L-REV', -width => '3', -he +ight => "$h")->pack(-expand => 1, -fill => 'both', -padx => 2, -pad +y => 2, -side => 'left', -ipadx => 5, -ipady => 5); $button34->configure(-background => "gray", -foreground => "black"); $balloon->attach($button34, -balloonmsg => "Left Reverse Speed"); $button34->bind('<ButtonPress>', \&leftrevspeedone); } sub leftfwdspeedone { $button34->configure(-text=>'L REV 0', -background => "gray", -foregro +und => "black"); $balloon->attach($button34, -balloonmsg => "Left Reverse Speed 0"); $button33->configure(-text=>'L FWD 0', -background => "gray", -foregro +und => "black"); $balloon->attach($button33, -balloonmsg => "Left Forward Speed 0"); $button33->bind('<ButtonPress>', \&leftfwdspeedtwo); } # END SUB sub leftfwdspeedtwo { $button34->configure(-text=>'L REV 0', -background => "gray", -foregro +und => "black"); $balloon->attach($button34, -balloonmsg => "Left Reverse Speed 0"); $button33->configure(-text=>'L FWD 10', -background => "gray", -foregr +ound => "black"); $balloon->attach($button33, -balloonmsg => "Left Forward Speed 10"); $button33->bind('<ButtonPress>', \&leftfwdspeedthree); } sub leftrevspeedone { $button33->configure(-text=>'L FWD 0', -background => "gray", -foregro +und => "black"); $balloon->attach($button33, -balloonmsg => "Left Reverse Speed 0"); $button34->configure(-text=>'L REV 0', -background => "gray", -foregro +und => "black"); $balloon->attach($button34, -balloonmsg => "Left Reverse Speed 0"); $button34->bind('<ButtonPress>', \&leftrevspeedtwo); } # END SUB sub leftrevspeedtwo { $button33->configure(-text=>'L FWD 0', -background => "gray", -foregro +und => "black"); $balloon->attach($button33, -balloonmsg => "Left Reverse Speed 0"); $button34->configure(-text=>'L REV 10', -background => "gray", -foregr +ound => "black"); $balloon->attach($button34, -balloonmsg => "Left Reverse Speed 10"); $button34->bind('<ButtonPress>', \&leftrevspeedthree); } # END SUB sub leftrevspeedthree { $button33->configure(-text=>'L FWD 0', -background => "gray", -foregro +und => "black"); $balloon->attach($button33, -balloonmsg => "Left Reverse Speed 0"); $button34->configure(-text=>'L REV 20', -background => "gray", -foregr +ound => "black"); $balloon->attach($button34, -balloonmsg => "Left Reverse Speed 20"); $button34->bind('<ButtonPress>', \&leftrevspeedfour); } # END SUB
Thanks in advance!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Tk Buttons
by Anonymous Monk on Nov 14, 2015 at 04:02 UTC | |
by PilotinControl (Pilgrim) on Nov 14, 2015 at 13:38 UTC | |
by Athanasius (Archbishop) on Nov 14, 2015 at 13:51 UTC | |
by PilotinControl (Pilgrim) on Nov 14, 2015 at 16:03 UTC | |
by choroba (Cardinal) on Nov 14, 2015 at 16:39 UTC | |
| |
by PilotinControl (Pilgrim) on Nov 14, 2015 at 13:58 UTC | |
by fishmonger (Chaplain) on Nov 14, 2015 at 14:47 UTC |