Home > Blockchain >  Is there a winforms designer for python?
Is there a winforms designer for python?

Time:01-05

So I was just wondering if there was a winforms editor like this for python?

I saw that iron python exists but I doesn't have a visual editor It's just text...

Image that shows what I am looking for:

Image that shows what I am looking for

CodePudding user response:

You can use either of the following options:

Example - Pass parameter from Windows Forms UI to a Python function

Here is an example of using IronPython in a C# Windows Forms app:

  1. Create a Windows Forms application.

  2. Install IronPython nuget package.

  3. Add using IronPython.Hosting; statement to the using statements.

  4. Drop a TextBox on the form (textBox1)

  5. Drop a Button on the form (button1)

  6. Double click on button and add the following code for the click handler:

    private void button1_Click(object sender, EventArgs e)
    {
        var engine = Python.CreateEngine();
        var scope = engine.CreateScope();
        //You can also load script from file
        var source = engine.CreateScriptSourceFromString(
            "def hello(name):"   "\n"  
            "    result = 'Hello, {}!'.format(name)"   "\n"  
            "    return(result)",
            Microsoft.Scripting.SourceCodeKind.Statements);
        var compiled = source.Compile();
        compiled.Execute(scope);
        dynamic hello = scope.GetVariable("hello");
        var result = hello(textBox1.Text);
        MessageBox.Show((string)result);
    }
    
  7. Press F5 to Run the application, enter a text, and click on the button. The function will run and you will see a message box saying hello.

Example source code

You can download or clone the example:

  • Related