wxPython:上下文对话框弹出窗口

时间:2010-07-14 05:03:26

标签: python wxpython

在Windows对话框中,有时右上角有一个小?按钮。它的用法是单击?,然后光标变为带有?的箭头,然后单击对话框内的窗口小部件,然后显示弹出式帮助气球。

这是我的班级定义的样子:

class Frame(wx.Frame):
  def __init__(self, parent, title):
    wx.Frame.__init__(self, parent=parent, id=wx.ID_ANY, title=title,
          style=(wx.DEFAULT_FRAME_STYLE | wx.WS_EX_CONTEXTHELP) ^ 
             (wx.RESIZE_BORDER | wx.MAXIMIZE_BOX | wx.MINIMIZE_BOX),
          pos=(20, 20))
    self.SetExtraStyle(wx.FRAME_EX_CONTEXTHELP)
    self.createOtherStuffHere()
    self.Show()

如何告诉小部件其帮助气球应该说:"This button cooks spam, ham, and eggs"

1 个答案:

答案 0 :(得分:4)

查看上下文帮助类

需要注意的重要事项是您必须初始化帮助提供程序,例如

provider = wx.SimpleHelpProvider()
wx.HelpProvider_Set(provider)

并为小部件设置帮助文本,例如

panel.SetHelpText("This is a wx.Panel.")

工作示例:

import  wx

class Frame(wx.Frame):
  def __init__(self, parent, title):
    wx.Frame.__init__(self, parent=parent, id=wx.ID_ANY, title=title,
                style=(wx.DEFAULT_FRAME_STYLE | wx.WS_EX_CONTEXTHELP) ,
                pos=(20, 20))
    self.SetExtraStyle(wx.FRAME_EX_CONTEXTHELP)
    self.CreateStatusBar()
    self.createOtherStuffHere()
    self.Show()

  def createOtherStuffHere(self):
    panel = wx.Panel(self)
    panel.SetHelpText("This is a wx.Panel.")

    self.label = wx.StaticText(panel, style=wx.WS_EX_CONTEXTHELP, label="Click me I may provide some help?", size=(200,30))
    self.label.SetHelpText("This is the help though not so helpful!")

    self.edit = wx.TextCtrl(panel, pos=(20,50))
    self.edit.SetHelpText("i am a edit box")

    self.helpButton = wx.ContextHelpButton(panel, pos=(20,100))

provider = wx.SimpleHelpProvider()
wx.HelpProvider_Set(provider)

app = wx.PySimpleApp()
frame = Frame(None, "Test")
app.SetTopWindow(frame)
app.MainLoop()