I have been using the wxPython demo code as a reference for writing my own
application. I have added a taskbaricon in my application using the tbicon
in the demo code as the reference. When I close my application using my exit
menu, it is only the frame that closes while the application and the
taskbaricon still runs. I added a tbicon.Destroy at the exit menu's handler
and it works fine. Upon examining the wxPython demo code's exit menu's
handler, I found this function definition:
def OnFileExit(self, *event):
self.Close()
and this works; it closes the app as well as the tbicon. I just want to ask
what is the difference between passing event and *event, and when do I use
one against the other?
In Python, seeing a function definition of the form...
def foo(arg1, *args):
print args
...means that args will take the value of a tuple of however many extra
arguments were passed. For example...
>>> foo(1, 2, 3)
(2, 3)
>>>
Similarly, if you have a bunch of arguments you want to pass, but you
have them in the form of a list or tuple, you can pass them all using a
similar syntax...
>>> foo(*(1,2,3))
(2, 3)
>>>
However, your function definition does not need to have a *varargs
parameter to support the receiving of list/tuple arguments...
>>> def goo(arg1, arg2):
... print arg1, arg2
...
>>> goo(*[1,2])
1 2
>>>
This is all covered in the Python tutorial available on python.org .
To answer the specific question you had, you would use OnFileExit(*event)
if event was a list or tuple, but OnFileExit(event) if it was just an
event. Then again, it doesn't matter, as it seems as though the
definition doesn't use the event argument at all, so you could get away
with not passing anything.
- Josiah
···
"Allan Noriel Estrella" <allan.noriel.estrella@gmail.com> wrote: