-1


I maked a script who need to pars 3D printer log files and export it to .xlsx.
I finished that but now I need to make GUI for that script, I finished almost everything except the one thing. I have function like this

def run(templatefilename):

#LIST OF PRINTER LOG FILES
listOfLogFiles = glob.glob(r"newPrintLogs\*.txt")

for logfile in listOfLogFiles:

    #PARSING PRINTER LOG FILE
    data = parsPrintingLog(logfile)

    #WRITE EXCEL FILE
    excelWrite(data, templatefilename)

    # MOVE FINISHED FILES
    dst = "finishedPrintLogs\\" + logfile.split('\\')[-1]
    src = r"" + str(logfile)
    shutil.move(src, dst)
    consoleLog(src + " " + "successfully finished and moved to" + " " + dst)
    # print (src, "successfully finished and moved to", dst)

and from this function I need to export the "# MOVE FINISHED FILES".
Before I've maked GUI I used print for printing where the log is moved, but now I don't know how to print it in GUI textbox, it's not necessary to be a textbox, I only need to show that in my GUI application.

galabl
  • 53
  • 2
  • 9

1 Answers1

0

Maybe i misunderstand your question, but from what I gathered you are wanting to dump the contents of your log file to be display in the tkinter GUI.

You could use a ttk ScrolledText widget.

Small minimal example"

textbox = ttk.ScrolledText(parent)
log_contents = open(log_file, "r").read()
textbox.insert("end", log_contents)

If you have some other encoding for your log file you could this for example in textbox.insert log_contents could be decoded to utf-8 by log_contents.decode("utf-8")

You can then handle scrolling, searching the scrolledtext widget highlight found words etc by additional methods to search your log files contents for example.

Pythonista
  • 11,377
  • 2
  • 31
  • 50
  • Not really, I need to export the "\print (src, "successfully finished and moved to", dst)\" to my GUI application, not log file. – galabl Aug 28 '15 at 09:19
  • So to clarify you need to insert the following text `src successfully finished and moved to dst` where src and dst are the source and destination directories to the GUI? If that;s the case then why not just define the textbox and then where the print line is do `textbox.insert("end", "%s successfully finished and moved to %s\n" % (src, dest))`? – Pythonista Aug 28 '15 at 09:20
  • NameError: name 'src' is not defined – galabl Aug 28 '15 at 09:38
  • Then you have errors in your code somewhere or in the structure `src` is clearly defined in the code block you posted in the question? and I made a small error in the above comment `dest` should be `dst` as denoted in your code block – Pythonista Aug 28 '15 at 09:39