Reputation: 22443
I have tried:
wx.ToolTip.Enable(False)
wx.ToolTip_Enable(False)
and
wx.ToolTip.Enable(flag=False)
none of theses instructions are rejected and yet none of them work
I'm using Linux Mint 17
wx.python 2.8.12.1 (gtk2-unicode)
python 2.7
Upvotes: 2
Views: 732
Reputation: 22443
The answer in the end for individual tooltips was gloriously simple and yet took an age to find.
Set the tooltip with SetToolTipString("my Tool Tip")
but remove it with SetToolTip(None)
see below:
The global turning on and off of tooltips still seems to be controlled by your desktop environment.
import wx
class MyForm(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Toggle")
self.panel = wx.Panel(self, wx.ID_ANY)
self.dummy = wx.StaticText(self.panel, -1, "")
self.cb1 = wx.CheckBox(self.panel, -1,"Choice 1", pos=(10,10))
self.cb2 = wx.CheckBox(self.panel, -1,"Choice 2", pos=(10,40))
self.cb1.Bind(wx.EVT_CHECKBOX, self.onToggle1)
self.cb2.Bind(wx.EVT_CHECKBOX, self.onToggle2)
self.cb1.SetToolTipString(wx.EmptyString)
self.cb2.SetToolTipString(wx.EmptyString)
#----------------------------------------------------------------------
def onToggle1(self, event):
if self.cb1.GetValue() == True:
self.cb1.SetToolTipString("Check Box 1 is Checked")
else:
self.cb1.SetToolTip(None)
def onToggle2(self, event):
if self.cb2.GetValue() == True:
self.cb2.SetToolTipString("Check Box 2 Is Checked")
else:
self.cb2.SetToolTip(None)
# Run the program
if __name__ == "__main__":
app = wx.App(False)
frame = MyForm()
frame.Show()
app.MainLoop()
Upvotes: 1
Reputation: 13206
According to the wxpython docs, ToolTip.Enable
seems to,
Enable or disable tooltips globally.
Note May not be supported on all platforms (eg. Cocoa).
Which I assume includes your platform...
Instead, you may need to set the tooltips for the window itself. There isn't a ToolTop_Enable
method I can see for the window but setting the tooltip to an empty string seems to do the trick for me,
import wx
app = wx.App()
frame = wx.Frame(None, -1, '')
frame.SetToolTip(wx.ToolTip(''))
frame.SetSize(wx.Size(300,250))
frame.Show()
app.MainLoop()
EDIT: Define a child tooltip class which can be enabled/disabled and defaults based on a global value.
import wx
EnableTooltips = False
class Tooltip(wx.ToolTip):
'''A subclass of wx.ToolTip which can be disabled'''
def __init__(self, string, Enable=EnableTooltips):
self.tooltip_string = string
self.TooltipsEnabled = Enable
wx.ToolTip.__init__(self, string)
self.Enable(Enable)
def Enable(self, x):
if x is True:
self.SetTip(self.tooltip_string)
self.TooltipsEnabled = True
elif x is False:
self.SetTip("")
self.TooltipsEnabled = False
app = wx.App()
frame = wx.Frame(None, -1, '')
tt = Tooltip('test')
frame.SetToolTip(tt)
frame.SetSize(wx.Size(300,250))
frame.Show()
app.MainLoop()
I'm not sure this will work dynamically (i.e. once you start the gui, the frame tooltips have been set and changing their value may not update).
Upvotes: 1