0

I am adding a GUI to a command line python program using Tkinter. So far, I have the existing program running as a subprocess in a text widget on my GUI. The usage for the original file is:

Python [SCRIPT] -i [PATH TO FILE]

I wanted to know if it is possible to change the "-i" argument so that I can replace it with an input from the Tkinter Open file dialog. If so, a nudge in the right direction would be very much appreciated! Thanks in advance.

toppock
  • 17
  • 1
  • What do you mean by "subprocess in a text widget"? You can't put a subprocess in a widget. Did you mean that the output of the subprocess is being inserted in the text widget? – Bryan Oakley Mar 15 '13 at 14:43

1 Answers1

0

The Open File dialog returns a string, like this one: C:/path/filename.cmd. Use the following line of code to retrieve it:

str = filedialog.askopenfilename()

You weren't clear enough on how exactly are you implementing this command. If it's implemented as a string of text, e.g. your program is set to write an exe file, all you have to do is insert the program in the string, like this:

text = "Python [SCRIPT] " + str + " [PATH TO FILE]"

Otherwise, make the Python code write another Python code with a string including this input and run it.

HebeleHododo
  • 3,620
  • 1
  • 29
  • 38