2010-07-14 32 views
0

在Windows對話框中,有時右上角有一個小的?按鈕。它的用法是點擊?,然後光標變爲帶有?的箭頭,然後點擊對話框中的小部件,該小部件將顯示一個彈出幫助氣球。wxPython:上下文對話框彈出

這是我的類定義看起來像:

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"

回答

3

查找到上下文幫助類

需要注意的重要事項是您必須初始化幫助提供者,例如

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

感謝。我將編輯我的原始帖子以顯示我的課程定義。我也會編輯它以使我的問題更清晰。 – Kit 2010-07-14 06:31:09

+0

謝謝!奇蹟般有效 :) – Kit 2010-07-15 05:15:39