Hello World

The .NET framework includes a GUI toolkit for writing desktop applications. This is called Windows Forms, and is contained in the System.Windows.Forms assembly.

It is easy to use. The following example creates a form (a window) with a label on it, and can be executed from the interactive interpreter:

import clr clr.AddReference('System.Windows.Forms')

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

form = Form(Text="Hello World Form") label = Label(Text="Hello World!")

form.Controls.Add(label)

Application.Run(form)



Starting the application loop (Application.Run(form)) takes control until you close the form: you can't enter any more commands in the interpreter until this is done.

The IronPython distribution comes with some example code in the tutorial directory: winforms.py. This starts the event loop, and puts the interpreter on a background thread. So long as this file is on your path (or in the same directory as ipy.exe), you can execute import winforms.

This allows you to create (and inspect) live GUI objects interactively, without the interpreter blocking.

The same application running on Linux is displayed here:



Back to Contents.