[IronPython] [Newbie] Problem with Getting Started code

Jimmy Schementi Jimmy.Schementi at microsoft.com
Sat Mar 6 10:44:10 CET 2010


> I've been trying the Getting Started example code (from
> http://ironpython.net/browser/gettingstarted.html) but I get an error
> message. The message is:-
> 
>   TypeError: unsupported operand type(s) for +: 'NoneType' and 'function'
> 
> and the code that causes it is this (marked line appears to be the cause of
> the error):-
> 
>     <input id="button" type="button" value="Junk 2 - Say Hello!" />
>     <script type="text/python">
>     def button_onclick(s, e):
>         window.Alert("Hello from Python!")
> --> document.button.onclick += button_onclick
>     </script>
> 
> Can anyone explain what the correct code would be?

Sorry for the confusion; that was recently changed to:

    document.button.events.onclick += button_onclick

This is because the following is ambiguous as to which is an event and which is a property (and Silverlight doesn't provide a reliable way to distinguish the two):

    document.button.onclick
    document.button.foo

So a new "events" method has been added to "HtmlObject", which allows for hooking arbitrary events. The documentation will be updated shortly.

Note: you'll have to use the latest bits to see this behavior; previous builds you'd have to do it the long way:

    from System import EventHandler
    from System.Windows.Browser import HtmlEventArgs
    document.button.AttachEvent("onclick", EventHandler[HtmlEventArgs](button_onclick))

~Jimmy



More information about the Ironpython-users mailing list