adding GUI to a python script

Hi experts,
I wrote a python script that does exactly what I want it to do:
Extract a specific string(s) from a file and copy/write them to a file output.qry.txt.
I would like your assistance or guidance in doing the following modification to the code (code should run on Win XP machine):
I would like to have simple GUI that will request the following items:
1.      File input (for the fileinput)
2.      File output (currenty its always output.qry.txt).

I would appreciate any suggestion or direction,
Thanks in advance.
Who is Participating?
peprConnect With a Mentor Commented:
Here the raw input case:

inputFilename  = raw_input('Input filename : ')
outputFilename = raw_input('Output filename: ')

print 'The selected file names'
print 'Input :', inputFilename
print 'Output:', outputFilename

# You can check whether the input filename exists. The import command 
# is usually put to the top of the source file.
import os
if os.path.isfile(inputFilename):
    print 'Input file found.'
    print 'Input file missing.'

Open in new window

It prints the following on the screen:

Input filename : fsdfdsfsdf
Output filename: sdfsfsdfsdfs

The selected file names
Input : fsdfdsfsdf
Output: sdfsfsdfsdfs
Input file missing.

Open in new window

Do you mean the real GUI (i.e. graphical) or only a kind of prompt in the console?

Use the raw_input() command for the later (

If you mean GUI, you have to decide whether you want to use the included Tcl/Tk based module Tkinter ( or some more modern like wxPython or wxQt.
WAS_InfraAuthor Commented:
Thanks Pepr for the prompt reply.
I am talking about the real GUI (window and buttons) what is the easiest way to achieve that?
I am attaching my original script below

Thanks in advance,

import fileinput

def findStart(line):
	start = line.find("[part ")
	return start

def getCurrentAndTotal(item):
	myStrList = item[item.find("["):item.find("]")].split(" ")
	total = int(myStrList[-1])
	current = int(myStrList[1])
	return [current, total]
qry = ""
lst = list()
times = list()
results = list()
myLen = len("Performing query: ")

for line in fileinput.input():
	n = findStart(line)
	if (n != -1): 
listLen = len(lst)
for index in range(listLen):
	total,current = getCurrentAndTotal(lst[index])
	if (total == current):
		lstStr = lst[index]
		lstStr = lstStr[lstStr.find("Performing query:")+myLen:len(lstStr)-1]
		qry = qry + lstStr
		qry = times[index] + "\n" + qry
		qry = ""
		lstStr = lst[index]
		lstStr = lstStr[lstStr.find("Performing query:")+myLen:len(lstStr)-1]
		qry = qry + lstStr
f = open("output.qry.txt", "w+")
for item in results:

Open in new window

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

For working with the real GUI, you must learn some windowing basics.  The GUI applications are built a bit differently than console applications.  To make it short, this will require more work than the raw_input().

I personally do not use Tkinter, but the following is probably a good tutorial

I personally do use wxPython (  If you know wxWidgets (, it may be your choice.

If you know and/or prefer Qt, then you should use the wxQt.

This may be the decision for a longer time. You should ask for details if you do not know.

If you choose to use wxPython, you might want to have a look at wxFormBuilder.

This will generate Python GUI code for you from a graphical design that you create.
Or you could use pepr's code to create a console application in Python and then use AutoIt to create a GUI.

This method may be slightly easier as I think AutoIT is easier to generate a GUI in.  Also, AutoIt can run any script from a GUI, so might be useful for you in the future.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.