Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with menubutton and menu dismissal

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
In my application I would like to be able to destroy (and recreate) a menubutton. The problem occurs if the menu is still posted when the menubutton is destroyed (i.e. no selection was made, or the user did not click outside the window). Under these circumstance, if the menubutton is then recreated, the menu is no longer dislayed properly (sometimes it won't display at all). I have tried "unpost"ing the menu before destroying the menubutton but this doesn't seem to have any effect.

The version of tcl/tk I'm using is 8.4 and the platform is Solaris. Below is the test code to reproduce the problem. Try clicking on the menu button when it comes up and waiting until the program destroys it -- then try to open the menu again. After some time and multiple clicks the menu usually reappears -- but this behavior is inconsistant and I would like it to be dismissed properly.

proc create {} {
menubutton .mb -text Sample -relief raised -menu .mb.menu
pack .mb
set m [menu .mb.menu -tearoff 0]
$m add radio -label One -command {}
$m add radio -label Two -command {}
}

create
after 10000 {destroy .mb; create}

Your help would be greatly appreciated!
 
Have you tried using "pack forget .mb"? Bob Rashkin
rrashkin@csc.com
 
Thanks for the suggestion, but I'm afraid it still exhibits the same behavior.
 
Well, I noticed a somewhat different behavior on my Windows 2000 box. On both Tcl 8.3.2 and 8.4b2, if the menu is posted but no items are active (the mouse isn't over the menu), there's no problem; it's as if nothing happened, and the menubutton and menu still work fine.

However, if there is an active item (the mouse is over an item), the destroy/create seems to occur, but then as soon as I move my mouse, wish crashes.

I've submitted this as a bug on SourceForge. You can monitor bug #601954 on the Tk Toolkit project to follow its resolution.

May I ask why you want to destroy and recreate a menubutton while the user is still able to interact with it? I wouldn't typically design an application that did that. Perhaps simply reconfiguring the existing menubutton would satisfy your requirements? - Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Thank you very much for the detailed response and for submitting the bug.

The application I am working on is an expanding/retracting toolbar that will be used to launch other programs. To create this effect, I destroy the buttons when the toolbar is "retracted" and recreate them when it is "expanded". I am a student (currently employed as an intern) and this is my first time using tcl/tk. If you have any suggestions or could recommend a better approach, I'd be grateful.

I did manage to solve the problem I was having by calling the function tk::MenuUnpost before destroying the menubutton.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top