[wxPython-users] Binding mouse clicks to toolbar button

Cody Precord codyprecord at gmail.com
Tue Sep 25 06:15:01 PDT 2007


On Sep 25, 2007, at 8:02 AM, wormwood_3 wrote:

> Worked perfectly! I would not have guessed that name, and had not  
> seen it yet (going through The Book).
>
> Is there a list of all event types for reference?
>
probably in the docs somewhere on the website.

You can also use the handy dir() function to get a full list of the  
events in the wx module.

import wx

for x in dir(wx):
	if x.startswith('EVT_'):
		print x

> Thanks again!
> -Sam
>
> ____________________________________
> ----- Original Message ----
> From: Cody Precord <codyprecord at gmail.com>
> To: wxPython-users at lists.wxwidgets.org
> Sent: Tuesday, September 25, 2007 8:56:03 AM
> Subject: Re: [wxPython-users] Binding mouse clicks to toolbar button
>
> Think your looking for wx.EVT_TOOL
>
> cody
>
>
> On Sep 25, 2007, at 7:49 AM, wormwood_3 wrote:
>
>> Hello all,
>>
>> I have been following this list for a while, and everyone seems
>> very helpful! I just started with wxPython, so hopefully this
>> question will not prove too difficult--
>>
>> I have a toolbar and a menubar currently in a very basic app. Right
>> now, I want them to effectively be the same, i.e. each menu item
>> will have a corresponding toolbar button that does the same thing.
>> Portion of my code with the menubar and the toolbar:
>>
>>         # 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.
>>
>> Thanks in advance for the help,
>> Sam
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: wxPython-users- 
>> unsubscribe at lists.wxwidgets.org
>> For additional commands, e-mail: wxPython-users-
>> help at lists.wxwidgets.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users- 
> help at lists.wxwidgets.org
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users- 
> help at lists.wxwidgets.org
>





More information about the wxpython-users mailing list