Search code examples
python-2.7tkintersubmenu

Tkinter menu widget: command to hide menu


My problem is the following

I have an application with some menus, which depending of the tasks executed, its options can be configured, namely, the activation or deactivation of some menu options to prevent de user to call something that would cause an undesired behavior of the application.

The problem is that there is the possibility of the user click on the menu and maintain it opened, while the application configures de menu. In fact the menu is changed, but then the menu can freeze and still open even after the mouse leave the menu. However, I noticed If I click outside the application with the mouse, the menu efectivelly closes, and everything goes back to normal, but the user may not be aware of that and can become stuck. Anyway, it is not a interesting behaviour. I think this is a bug of the menu widget, but i'm not sure.

I cannot disable all the menu because there are options that in fact should be available. A solution would be a command to hide de menu after configure him, avoiding that situation. I tried use the "unpost" method, but nothing happened.

There is such possibility or any workaround that can solve my problem?

I leave some images of the aforementioned menu to ilustrate my problem:

Normal

Normal

Disabling some options

Disabling some options

The "bug" situation

the "bug" situation


Solution

  • Luckily I think I found the source of this misbehaviour. After configuring the menu, another window (a custom made warning message) is displayed. To force the user to pay attention to that message, the focus was given to it, and the application was forced to wait (using the wait_window" method) until the user closes it. The "wait_window" was causing the issue, because it was not allowing the mainloop to hide the menu since it was waiting for the closing of the warning window, but somehow it is not possible to close the window without the menu hides first. It is a kind of "priority conflict" situation.

    enter image description here

    The solution was not use that method, and the menu closes as desired.

    I think this may be usefull to anyone getting this trouble in the future