in reply to Re: Tk starting and stopping an autoplay loop using a keybinding
in thread Tk starting and stopping an autoplay loop using a keybinding

Or, a bit shorter:

$toggle_autoplay ^= 1;

Just to confuse things,

$toggle_autoplay == 0 ? $toggle_autoplay = 1 : ($toggle_autoplay = 0);

would have worked (because it fixes the precedence problem you were having).