-1

I am currently trying to write a User Interface for a program, that is only used via command line. It has several mandatory and optional parameters but you really only need one line to execute it. Now I am wondering how I can "link" my python script to the command line and make it execute the program when I click a "Run-Button".

I am just starting to get into TKinter and Python programming, so I need very basic instructions.

I am on a Linux-System (Ubuntu 16.10) using Python 3.5 and Tkinter.

Thank you.

lenala
  • 19
  • 5
  • You will get higher quality answers if you provide simple examples of what code you have already. If the script that you want to run is a python program then it would be more efficient to import the code in to your tkinter code and call it when the button is pressed, passing the appropriate arguments. – scotty3785 Sep 20 '17 at 10:41
  • So do you have a script file you have written separately which consists of this command line execution and you need to know how to trigger that with tkinter? – Ethan Field Sep 20 '17 at 10:55
  • Yes, exactly that @EthanField . I did now find the option of `os.popen(command)`. – lenala Sep 20 '17 at 12:03
  • Whilst you're not using a .bat file, this may be of some help to you: https://stackoverflow.com/questions/5469301/run-a-bat-file-using-python-code – Ethan Field Sep 20 '17 at 12:13

1 Answers1

0

For command line use, check this module: subprocess

In your GUI code

create a start Button:

Button(master, text='RUN', bg='green',fg='white', command=Run-Button).grid(row=0, pady=4)

and a function definition attached to it:

def Run-Button():
     subprocess.call(["ls", "-l"]) #use your command to run
Heikki
  • 2,214
  • 19
  • 34
Varada
  • 736
  • 7
  • 17