[wxPython-users] Binding mouse clicks to toolbar button
Andrea Gavana
andrea.gavana at gmail.com
Tue Sep 25 05:54:26 PDT 2007
Hi Sam,
On 9/25/07, wormwood_3 wrote:
> # Add a tool bar:
> toolbar = self.CreateToolBar()
> helpbutton = toolbar.AddSimpleTool(wx.NewId(), wx.Image('resources/help-browser.png',
> wx.BITMAP_TYPE_PNG).ConvertToBitmap(), 'Help', 'Help for Domainspotter')
> self.Bind(wx.EVT_LEFT_DOWN, self.ShowHelp, helpbutton)
> exitbutton = toolbar.AddSimpleTool(wx.NewId(), wx.Image('resources/system-log-out.png',
> wx.BITMAP_TYPE_PNG).ConvertToBitmap(), 'Exit', 'Long help for Exit')
> self.Bind(wx.EVT_LEFT_DOWN, self.OnCloseMe, exitbutton)
> toolbar.Realize()
> # Add a menu bar:
> menubar = wx.MenuBar()
> menu1 = wx.Menu()
> menubar.Append(menu1, "&File")
> exititem = menu1.Append(wx.NewId(), "&Exit", "Exit Domainspotter")
> self.Bind(wx.EVT_MENU, self.OnCloseMe, exititem)
> menu2 = wx.Menu()
> menubar.Append(menu2, "&Help")
> aboutitem = menu2.Append(wx.NewId(), "&About", "About Domainspotter")
> self.Bind(wx.EVT_MENU, self.ShowAbout, aboutitem)
> helpitem = menu2.Append(wx.NewId(), "Help", "Domainspotter Help")
> self.Bind(wx.EVT_MENU, self.ShowHelp, helpitem)
> self.SetMenuBar(menubar)
>
> and then the associated functions mentioned in the Bind()'s:
>
> def OnCloseMe(self, event):
> self.Close(True)
>
> def ShowAbout(self, event):
> abouttext = wx.MessageDialog(self, self.abouttext, caption = "About Domainspotter",
> style = wx.OK | wx.ICON_INFORMATION)
> abouttext.ShowModal()
> abouttext.Destroy()
>
> def ShowHelp(self, event):
> helptext = wx.MessageDialog(self, self.helptext, caption = "Domainspotter Help",
> style = wx.OK | wx.ICON_INFORMATION)
> helptext.ShowModal()
> helptext.Destroy()
>
> The menubar items work just fine. Help and about show help and about, and exit exits. But, when I press the Help or Exit buttons, which are bound to the same functions, nothing happens. No errors either.
>
> My guess is that I have the wrong event specified in the self.Bind for the buttons. I tried wx.EVT_BUTTON as well, same deal.
Instead of wx.EVT_LEFT_DOWN, try to do something like:
self.Bind(wx.EVT_TOOL, self.OnCloseMe, id=exitbutton.GetId())
Andrea.
"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/
More information about the wxpython-users
mailing list