views:

179

answers:

2

I have been doing Michael Foord's IronPython&Winforms tutorials in the interactive console.

Is it possible to remain in the console after the issueing

Application.Run(form)

so, I can put controls on the form while it is running?

The goal is to dynamically modify the WinForms controls at runtime, adding event handlers, changing properties etc.

+1  A: 

You have to run the Application.Run(form) in different thread. See my blog post or Michael's one: www.voidspace.org.uk/python/articles/testing/testing-multidoc.shtml

Lukas Cenovsky
+2  A: 

With my installation (think I used the MSI) there is a Tutorial folder directly under the main IronPython one.

Inside the folder there is a Tutorial.htm file that has an example of just what you want, in the Tutorial 2 -> Exercise 2 : Windows Forms section.

Essentially you have to make sure the IronPython knows about the winforms.py file provided in the Tutorial folder, by either having it on the path or launching IronPython from a folder containing a copy of the file.

Then you can do

 import winforms
 from System.Windows.Forms import *
 from System.Drawing import *
 f = Form()
 f.Show()

Which will bring up a form for you, but leave the console interactive so you can change the form as you want to while it is running.

Argos
Great tip. I tried running this example from an IronPython console under eclipse with no success. You need to launch ipy.exe from a plain old command prompt.
pdemarest