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:
CodePudding user response:
You can use either of the following options:
- Pygubu designer for pygubu
- Qt designer for PyQt
- Windows Forms designer in Visual Studio and run the code using IronPython.
Example - Pass parameter from Windows Forms UI to a Python function
Here is an example of using IronPython in a C# Windows Forms app:
Create a Windows Forms application.
Install IronPython nuget package.
Add
using IronPython.Hosting;
statement to the using statements.Drop a
TextBox
on the form (textBox1)Drop a
Button
on the form (button1)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); }
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:
- Download: Zip
- Repository: r-aghaei/WinFormsIronPythonExample