Perl Monk, Perl Meditation | |
PerlMonks |
Setting options in Tk::Optionmenu without the callback?by graff (Chancellor) |
on Aug 22, 2007 at 22:32 UTC ( [id://634530]=perlquestion: print w/replies, xml ) | Need Help?? |
graff has asked for the wisdom of the Perl Monks concerning the following question:
I need to change the entries in a Tk::Optionmenu widget whenever the user does something in another widget. No problem with that, but every time this happens, it triggers the Optionmenu widget's "-command" (callback) subroutine.
Of course, when the user actually clicks on the Optionmenu widget and selects one of the current menu items, this runs the callback with the menu value chosen by the user, and this is fine. My problem is, how can the callback function tell the difference between being invoked by an actual menu selection (user has made a choice, so do something with that) vs. being invoked because the options have been changed (user hasn't really picked a specific option, so don't do anything yet). Here's a little test script demonstrates the behavior: when the window first starts up, the first installation of options invokes the callback. Thereafter, the callback is invoked when the Optionmenu itself is used to make a selection, and each time the "Change Options" button is clicked. I want the callback to be able to skip its work (or not be called in the first place) when installing a new menu. How do I do that?
I've looked at the source (Optionmenu.pm), and I could create a modified version of this widget, altering its "addOptions" and "setOption" functions so that the latter does not invoke the callback whenever it happens to be called by the former... But creating a new version of a widget is the sort of thing I'm likely to do wrong the first few times I try, so I'm hoping some monk can guide me (actually, I'm hoping there's an easier work-around that I'm missing).
Back to
Seekers of Perl Wisdom
|
|