How to properly handle menus in pyROOT

Dear ROOTers,

I am not sure how to properly handle menus in a pyROOT GUI app. I attach a modified tutorial example gui_ex.py, where I’ve added 2 menus. There are two problems with this example:

  1. If I select File->About, I get a proper message box. However, if I later select File2->About, I still get the message box attached to File->About, instead the one attached to File2->About. The reason is, that self.MenuFile.GetCurrent() does not return None after it has been used once, and I use this to recognise which menu was selected.
  2. The program crashes after selecting the first menu, dismissing the message box, then selecting the second (showing the first message box) and dismissing the message box.

I would be grateful for any advise. Running on python 2.7.

gui_ex.py (3.2 KB)


ROOT Version: 6.21


Hi @LeWhoo ,

I’ll check your example and report back!

Try that way:

        def handle_menu(self, id):
                print "handle_menu: id = ", id
                if id == 31:
                        self.ShowMsg()
                else:
                        self.ShowMsg2()
                [...]

        def __init__( self, parent, width, height ):
                ROOT.TGMainFrame.__init__( self, parent, width, height )
                [...]
                self.MenuFile.Connect("Activated(Int_t)", "TPyDispatcher", self.mdisp, "Dispatch(Int_t)")
                self.MenuFile2.Connect("Activated(Int_t)", "TPyDispatcher", self.mdisp, "Dispatch(Int_t)")
                [...] 

But I don’t know why it crashes…

1 Like

Thanks! That works!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.