ComboBox条目的帮助文本

时间:2016-05-17 14:49:26

标签: wxpython

我的一个屏幕上有一个ComboBox,其中'类型的运动'参与的客户(主要是职业体育人士)可以选择。这样做是为了避免所有可能的运动列表过长。一个例子是' Board sports'这与软件的滑板,滑板,冲浪等有关。该软件的许多用户询问,如果将帮助文本悬停在选项上,例如,可以显示帮助文本。如果他们徘徊在&Board;将显示所提到的运动。经过几个小时的谷歌搜索后,我看不到怎么做。是否可能,如果可能,怎么样?

1 个答案:

答案 0 :(得分:1)

这是" a"解决方案,选择然后悬停:

import wx

class Myframe(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None)
        self.my_choices = ["Board Sports","Ball Sports","Fight Sports"]
        self.my_subchoices = [["Skate boarding","Surfing","Ski boarding"],["Football","Cricket","Rugby","Guess my nationality"],["Boxing","Wrestling","Karate"]]
        pan = wx.Panel(self)
        self.cbx = wx.ComboBox(pan, -1, pos=(10,30), choices=self.my_choices,style=wx.CB_DROPDOWN )
        self.cbx.Bind(wx.EVT_COMBOBOX, self.on_selection)
        self.cbx.SetValue("Choose a sport")

    def on_selection(self, evt):
        Choice = self.cbx.GetSelection()
        msg = ""
        for x in self.my_subchoices[Choice]:
            msg += x+"\n"
        self.cbx.SetToolTipString(msg)

if __name__ == "__main__":  
    App = wx.App()
    Myframe().Show()
    App.MainLoop()