简体   繁体   中英

Converting Python command line input to Tkinter Open file dialog widget

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.

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, eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM