Я хочу создать приложение для Windows, используя Visual Basic и Visual Studio 2017. Здесь я хочу запустить внешний скрипт Python, который будет запускаться при нажатии кнопки 1 в форме Windows. Он будет вводить данные из текстового поля формы и выполнять некоторые вычисления, а затем возвращать результат и возвращать его в текстовое поле формы.
Код python может быть следующим:
r = input()
p = 2*3.14*r
print(p) #Instead of print(p) something that can return the value to the form
Или это:
def peri(r):
p = 2*3.14*r
return p
Мне удалось найти для вас это решение, и я очень надеюсь, что оно сработает:
1.Write your python code , for example : print("Hello world python !!") in text file and save to .py
2.Create project at VB.NET, drag component 1 button and 1 textbox into form.
3.Double click button1, at event click button1 write this code
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim proc As Process = New Process
proc.StartInfo.FileName = "C:\Python34\python.exe" 'Default Python Installation
proc.StartInfo.Arguments = pathmypythonfile.py
proc.StartInfo.UseShellExecute = False 'required for redirect.
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden 'don't show commandprompt.
proc.StartInfo.CreateNoWindow = True
proc.StartInfo.RedirectStandardOutput = True 'captures output from commandprompt.
proc.Start()
AddHandler proc.OutputDataReceived, AddressOf proccess_OutputDataReceived
proc.BeginOutputReadLine()
proc.WaitForExit()
TextBox1.Text = Value
End Sub
Public sub proccess_OutputDataReceived(ByVal sender As Object, ByVal e As DataReceivedEventArgs)
On Error Resume Next
If e.Data = "" Then
Else
Value = e.Data
End If
End sub
4. Create module file, and write this variable global :
Module module
Public Value As String
End Module
5. Running the application, if textbox1 have populated with some string then your code was success.
ЗДЕСЬ - это завершение полного процесса.
Я не слишком знаком с этим, но вы можете изучить железный питон