Winfrom Desktop program calls Python interpreter

Source: Internet
Author: User

Winfrom Desktop Program calls the Python interpreter executes the py script background execution to complete the specific function, why should this be handled? Because I now most of the project is the background of the script processing, the interface basic input is completed, the parameters in accordance with the rules passed to the entrance of the script, according to the different parameters to execute different script process, if you want to modify a process or add a new module, do not need to modify the foreground of any code, Only need to modify in the script can achieve the effect of demand, simple, convenient, less risk, the impact of controllable and other advantages.

Therefore, I have made a demo, only for reference, deficiencies, please enlighten!

Interface

The execution code for START_EXE_PY is as follows:

1  Private voidStart_exe_py_click (Objectsender, EventArgs e)2         {3             stringTxtname = This. TextName.Text.Trim ();4             stringCurentpath =System.Windows.Forms.Application.StartupPath;5             stringPyexecpath = Curentpath +@"\.. \3rdtools\python27\python.exe";6             stringPyworkingdir = Curentpath +@"\.. \";7             stringPyfilepath = Curentpath +@"\.. \userdefinedscripts\main.py";8             stringPYARGV ="";9PYARGV =" "+txtname;Ten  OneCursor.current =Cursors.waitcursor; AProcess Pro =NewProcess (); -  -             //do not show Windows thePro. Startinfo.redirectstandardoutput =true; -Pro. Startinfo.useshellexecute =false; -Pro. Startinfo.createnowindow =true; -              +             //Display window -             //Pro. Startinfo.redirectstandardoutput = false; +             //Pro. Startinfo.useshellexecute = true; A             //Pro. Startinfo.createnowindow = false; at  -Pro. Startinfo.filename =Pyexecpath; -Pro. Startinfo.workingdirectory =Pyworkingdir; -Pro. Startinfo.arguments = Pyfilepath +pyargv; - Pro. Start (); -  in Pro. WaitForExit (); -Cursor.current =Cursors.Default; to}

The specific directory structure method reference:

User-definable script code:

1 #!/usr/bin/env python2 #-*-coding:utf-8-*-3 #@Date: 2016-06-30 09:10:444 #@Author: Stlong5 #@Version: 1.06 7 ImportOS8 ImportSYS9 Ten defMain (): One     Print "Hello python!" A     PrintRaw_input ("python input:") -  -      the if __name__=='__main__': -     PrintSys.argv[0] -     PrintSys.argv[1] -Main ()

Due to the lack of time relationship, please forgive me!

Winfrom Desktop program calls Python interpreter

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.