IronPython学习 之hello word.


 
IronPython Python 语言在 .NET 平台上的实现,它是一个完全动态的交互式解释器,可以支持所有的.NET类型库,需要.NET Framework 2.0的支持。
 
IronPython1.0 下载
http://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=IronPython&ReleaseId=423

安装很简单:设置环境变量就可以了
PAHT:
IronPython1.0路径 如 : path D:\IronPython-1.0


简单例子

myFistPython.py

import clr
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Data")
clr.AddReferenceByPartialName("System.Drawing")

from System.Collections import *
from System.Windows.Forms import *
from System import *
from System.Data import *
from System.Data.SqlClient import *
from System.Drawing import *


class HelloWord(Form):
    def __init__(Word):
            Word.Text='hello'
            Word.ClientSize=Size(600,455)
      # 添加个button
        myButton =Button()
        myButton.Text="sa Hello wujun"
        myButton.Location =Point(12,136)
        myButton.Click += Word.myButton_Click
        Word.Controls.Add(myButton)
       
        #添加个listBox
        myListBox =ListBox()
        myListBox.Location=Point(12,12)
        Word.Controls.Add(myListBox)
       
        #添加个datagridView
        myDataGridView =DataGridView()
        myDataGridView.Location=Point(12,165)
        myDataGridView.Size=Size(550,350)
        Word.Controls.Add(myDataGridView)
       
        #简单的链接数据库 绑定 DataGridView
        sql = String()
        conStr =String()
        sql="select * from orders"
        conStr="server=.;uid=sa;pwd=cwave;database=Northwind"
        sa =SqlDataAdapter(sql,conStr)
        ds =DataSet()
        sa.Fill(ds)
        myDataGridView.DataSource=ds.Tables[0]
       
       

        array=ArrayList()
        #循环
        for i in xrange(100):
          array.Add(i)
         
          #绑定到 ListBox
        myListBox.DataSource =array
     
     # 定义事件    
    def myButton_Click(Word, *args):
        MessageBox.Show("hello word","欢迎来到神奇的世界")
     # 中文乱码噢???

Application.Run(HelloWord())

编译 假设
myFistPython.py 放在C盘

运行dos 进入c盘  C:\> ipy 
myFistPython.py


运行结果:



相关网站:

http://www.python.org/
http://www.codeplex.com/Wiki/View.aspx?ProjectName=IronPython

http://wiki.woodpecker.org.cn/moin/

http://blogs.msdn.com/hugunin/


http://blogs.msdn.com/hugunin/

posted on 2006-09-15 16:35  hello csharp  阅读(6417)  评论(7编辑  收藏  举报

导航