Search code examples
pythonwxpythontooltip

wxPython - Add tooltip to menu items


How do I add tooltips to elements of a wx.Menu()? Here's the code I've written for the items:

#Patient menu (1st menu):
self.patientMenu = wx.Menu()
self.registerNewPatient = self.patientMenu.Append( -1, 'Cadastrar paciente...' )
self.listPatientsByName = self.patientMenu.Append( -1, u'Listar pacientes em ordem alfabética' )
self.listPatientsByNumber = self.patientMenu.Append( -1, u'Listar pacientes por número em ordem crescente' )
self.searchForPatients = self.patientMenu.Append( -1, 'Pesquisar paciente(s)...' )
#Appointment menu (2nd menu):
self.appointmentMenu = wx.Menu()
self.seeAppointmentsForToday = self.appointmentMenu.Append( -1, 'Visualizar consultas de hoje' )
self.registerNewAppointment = self.appointmentMenu.Append( -1, 'Marcar consulta...' )
self.cancelAppointment = self.appointmentMenu.Append( -1, 'Desmarcar consulta...' )
self.seeAppointmentsForOtherSpecificDate = self.appointmentMenu.Append( -1, 'Pesquisar consultas...' )
#Exit menu (3rd menu):
self.exitMenu = wx.Menu()
self.exitProgram = self.exitMenu.Append( -1, 'Encerrar' )
#Menu bar:
self.menuBar = wx.MenuBar()
self.menuBar.Append( self.patientMenu, 'Paciente' )
self.menuBar.Append( self.appointmentMenu, 'Consulta' )
self.menuBar.Append( self.exitMenu, 'Sair' )
self.SetMenuBar( self.menuBar )

Solution

  • From what I could gather it looks like the consensus is that you would want to bind an event to listen to wx.EVT_MENU_HIGHLIGHT or wx.EVT_LIST_ITEM_SELECTED then grab the id of the selected menu perhaps with GetMenuId and using some sort of map/dict display the help message, or it looks like it might be possible to Set the help string Although it looks like this could be another possible solution:

    Also see balloontip:

    I am not sure if this is still the case, as some of these answers are a bit dated.

    Related: