views:

31

answers:

1

In Windows dialog boxes, sometimes there is a small ? button on the upper right corner. Its usage is to click on the ?, then the cursor changes to an arrow with a ?, then click on widget inside the dialog box, which will then display a popup help balloon.

This is how my class definition looks like:

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

How do I tell a widget that its help balloon should say: "This button cooks spam, ham, and eggs"

+1  A: 

Look into context help classes

Important thing to note is you have to initialize help provider e.g.

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

and set help text for widgets e.g.

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

Working example:

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()
Anurag Uniyal
Thanks. I'll edit my original post to show my class definition. I'll also edit it to make my question's idea clearer.
Kit
Thanks! Works like a charm :)
Kit