#!/usr/local/bin/perl use strict; use warnings; use Tk; require Tk::BrowseEntry; ######################### #Hitting the button casuses many instances of listBrowse widget ######################## my $main= MainWindow->new(); my $listButton=$main->Button( -text=> 'list', -height=> 2, -width=> 10, -relief=> 'ridge', -command=> \&listBrowse, )->pack(); my $choice="number"; #the default list item. sub listBrowse{ my $listTag=$main->BrowseEntry( -variable=>\$choice, -browsecmd=>\&Verify )->pack(); $listTag->insert("end","Number"); $listTag->insert("end","Bullet"); } MainLoop;
The button method of Tk doesn't have an option like "-variable" that can make me control this behavior in a better way. Though, I suspect an option like "-default" can be handy, I couldn't get hold of documentation for it when I checked around. So I've tried to manually introduce a flag which changes value when the button is pushed, I couldn't figure out how to implement this flag into some useful logic that could allow the list button to be hit only once. Ergo my reversion to the revered panel of Monks for guidance on how to be able to hit a button and activate the consequent action only once and not more than once.
UPDATE: I've used the tip provided by lamprecht and could extend on it to re-enable the disabled button and refresh the entire widget anew. SuicideJunkie, the second paragraph from your post was an inspiration. I was trying to use the flag the same way and introducing the same extra scope before I posted this question and it couldn't work in this block though another part of the application used a flag effectively. Thank ya'all.
#the steps in the refresh were to enable a disabled widget and destroy + a created #widget, these two behaviors can be kept under a button to + work simultaneously $listButton->configure(-state=>'normal'); $listTag->destroy if Tk::Exists($listTag);
In reply to better control of Tk::Button by biohisham
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |