Skip to content

Pac-Dessert1436/Run-Python-in-WinForms

Repository files navigation

Running Python Scripts in WinForms Application

This VB.NET project enables the execution of Python scripts within a Windows Forms application. It's designed to harness the flexibility and power of Python in conjunction with the user interface capabilities of WinForms.

Project Overview

Python scripts for this application are stored in the "PyScripts" folder, providing a centralized location for easy management and access.

Python Main Function Specification

To ensure that the output from your Python scripts is properly captured and displayed by the WinForms application, the main function in your Python scripts must be defined according to the following guidelines:

With Arguments

If your script is designed to accept arguments, the main function should take a StringIO object for output and a list of arguments of any type. The function should print to the StringIO object and return its contents.

from io import StringIO


def main(output: StringIO, args: list) -> str:
    # Join arguments and print to output
    print(str().join(args), file=output)
    # Return the contents of the output buffer
    return output.getvalue()

Without Arguments

If your script does not require arguments, the main function can be simplified to only accept a StringIO object.

from io import StringIO


def main(output: StringIO) -> str:
    # Print a message to output
    print("Hello world!", file=output)
    # Return the contents of the output buffer
    return output.getvalue()

How to Use

To use this project, simply place your Python scripts in the "PyScripts" folder, ensuring they adhere to the main function definitions provided. The WinForms application will execute your scripts and display their output.

Contributing

While this project is currently a solo endeavor, I am open to collaboration. If you're interested in contributing, please reach out to discuss potential enhancements, bug fixes, or new features.

License

This project is released under the MIT License. Feel free to use, modify, and distribute this project, provided you comply with the terms of the license.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published