[python-win32] Excel - accessing a control's properties in an event handler
Sriram Sundararajan
sriram.sundararajan at gmail.com
Fri May 9 18:37:58 CEST 2008
I have a question on the excelAddin.py sample in the win32com\demos folder.
We create a Tool Bar, add a button to it,
btnMyButton = cbcMyBar.Controls.Add(Type=constants.msoControlButton,
Parameter="Greetings")
'register' the button with the ButtonEvent class,
btnMyButton=self.toolbarButton = DispatchWithEvents(btnMyButton, ButtonEvent)
and set a couple of properties.
btnMyButton.Caption = "&Python"
btnMyButton.TooltipText = "Python rules the World"
In the OnClick event handler of the ButtonEvent class,
class ButtonEvent:
def OnClick(self, button, cancel):
1. How is the 'button' argument related to the actual button that was
clicked? It showed up as a PyIDispatch object when I tried printing
it.
2. Assuming there is more than one button that can be clicked, how
would I access some of the properties of the button instance that was
actually clicked by the user?
Thanks
Sriram
More information about the python-win32
mailing list