IronPython的Hello World

在上一篇随笔 “用Ironpython写winform程序” 里,写了一个显示窗体,这篇在此基础上添加了一个按钮,点击弹出对话框

用NotePad写一个文本文件,内容:

#导入名空间
from System.Windows.Forms import *
from System.Drawing import *

#窗体
f = Form()
f.Text = "Python Hello World"
#按钮
b = Button()
b.Text = "Click Me"

f.Controls.Add(b)

#定义按钮的事件
def buttonClick(data,event):
MessageBox.Show("Hello World!!")

b.Click += buttonClick
f.ShowDialog()

另存或改为py后缀,这里存成test.py文件
运行后效果:

Published At
Categories with Web编程
Tagged with
comments powered by Disqus