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!


In reply to Tk Buttons by PilotinControl

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.