in reply to Re^4: Tk Buttons
in thread Tk Buttons

That's weird. Why are you changing the binding? You should just change the speed. Here's how I understood your description:
#!/usr/bin/perl use warnings; use strict; use Tk; { my $speed = 0; sub change_speed { my $diff = shift; my $state = $speed <=> 0; if (! $state || $state == ($diff <=> 0)) { $speed += $diff if abs($speed + $diff) <= 100; } else { $speed = 0; } } sub create_label { my $parent = shift; return $parent->Label(-textvariable => \$speed, -relief => 'sunken', )->pack(-ipadx => 5) } } my $mw = 'MainWindow'->new(-title => 'Motor'); my $mf = $mw->Frame->pack; $mf->Label(-text => 'Tk Motor Controller')->pack; my $l = create_label($mf); my $bf = $mf->Frame->pack; $bf->Button(-text => '<', -command => [ \&change_speed, -10 ], )->pack(-side => 'left'); $bf->Button(-text => '>', -command => [ \&change_speed, 10 ], )->pack(-side => 'right'); my $qb = $mf->Button(-text => 'Quit', -underline => 0, -command => sub { Tk::exit() }, )->pack( -pady => 10); $mw->bind('<Alt-q>', sub { $qb->invoke }); MainLoop();

Update: Used closure over the $speed variable.

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^6: Tk Buttons
by PilotinControl (Pilgrim) on Nov 26, 2015 at 19:15 UTC

    That works great and that is what I was after...now each time the button is clicked it is suppose to increase and decrease the speed...do I just add the motor command....via serial port....to the &change_speed sub routine?