开发者

Why is IronPython code failing?

开发者 https://www.devze.com 2023-01-06 23:49 出处:网络
I am working through IronPython in Action. The following code fails at the line that reads label=Label()

I am working through IronPython in Action.

The following code fails at the line that reads label=Label()

The error returned is NameError: name 'Label' is not defined

This is exactly as in the book. And I don't know why it can't resolve the Label class...especially since it resolves the Form class with no problems. Any ideas?

Seth

import clr
clr.AddReference('System开发者_如何学运维.Windows.Forms')


from System.Windows.Forms import Application,Form
form=Form()
form.Text='Hello World'
label=Label()
label.Text='Wassup'
form.Controls.Add(label)

Application.Run(form)


Change:

from System.Windows.Forms import Application,Form

To:

from System.Windows.Forms import Application,Form,Label

Right now, the runtime doesn't know that "Label" is System.Windows.Forms.Label

0

精彩评论

暂无评论...
验证码 换一张
取 消