Skip to main content
 首页 » 编程设计

python之wxPython之向菜单项添加工具提示

2025年05月04日9myhome

如何向 wx.Menu() 的元素添加工具提示?这是我为项目编写的代码:

#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 ) 

请您参考如下方法:

据我所知,大家似乎一致认为您希望绑定(bind)一个事件来监听 wx.EVT_MENU_HIGHLIGHT或 wx.EVT_LIST_ITEM_SELECTED然后捕获 id所选菜单的可能与 GetMenuId 并使用某种 map/dict 显示帮助消息,或者看起来有可能 Set the help string尽管看起来这可能是另一种可能的解决方案:

另见 balloontip :

我不确定情况是否仍然如此,因为其中一些答案有点过时了。

相关: