0

I am trying to create a GUI for the analyzeMFT python program. So far this is what i have

#!/usr/bin/python # -*- coding: utf-8 -*- from Tkinter import * from ttk import * import analyzeMFT class Example(Frame): def __init__(self, parent): Frame.__init__(self, parent) self.parent = parent self.filename = "" self.initUI() def initUI(self): self.parent.title("Mtf Analyzer") #initializing and configuring menubar menubar = Menu(self.parent) self.parent.config(menu=menubar) fileMenu = Menu(menubar) fileMenu.add_command(label="Open file", command=self.fileOpen) fileMenu.add_command(label="Exit", command=self.onExit) menubar.add_cascade(label="File", menu=fileMenu) #specify grid row and column spaces self.pack(fill=BOTH, expand=True) self.columnconfigure(1, weight=1) self.columnconfigure(3, pad=7) self.rowconfigure(3, weight=1) self.rowconfigure(5, pad=7) lbl = Label(self, text="File Name") lbl.grid(row=1, column=0, sticky=W, pady=4, padx=5) filename_area = Entry(self) filename_area.grid(row=1, column=1, columnspan=3, padx=5) analize_button = Button(self, text="Analize", command=self.processFile) analize_button.grid(row=1, column=4, padx=5) area = Text(self) area.grid(row=2, column=1, columnspan=2, rowspan=4, padx=5, sticky=E+W+S+N) #configure the raw output view def onExit(self): self.quit() #this function selects and opens the file to analize def fileOpen(self): from tkFileDialog import askopenfilename Tk().withdraw() self.filename = askopenfilename() #populate the filename field #do the processing of the file obtained. Populate the file NAME entry or #send the filename to the analyzeMFT.py def processFile(self): filei = "-f "+self.filename arguments = [filei, '-o '+self.filename+' .csv'] analyzeMFT.main(arguments) #get and set methods for the entry field def get(self): return self.filename_area.get() def set(self, value): filename_area.set(value) def main(): root = Tk() root.geometry("250x150+300+300") app = Example(root) root.mainloop() if __name__ == '__main__': main() 

This code creates a gui that i can chose a file to analyze using the analyzeMFT program. There are two problems.

1.analyzeMFT is meant to be run on command line. I am not able to pass the file name I get from the GUI to the analyzeMFT.py Here are the contents of analyzeMFT.py

 #!/usr/bin/python try: from analyzemft import mftsession except: from .analyzemft import mftsession def main(): session = mftsession.MftSession() session.mft_options() session.open_files() session.process_mft_file() if __name__ == "__main__": main() 

Next, when i run the analyzerMFT in cmd and enable debug mode, it prints every detail on the screen. How can I direct that out to a window i have shown below enter image description here

I want it somehow to look like this enter image description here

Sorry if the explanation is very long. I've been working on it for days.

1 Answer 1

1

Instead of using print like you would normally use to display results to the console you can use insert() on your text box.

EDIT:

First change:

area = Text(self) area.grid(row=2, column=1, columnspan=2, rowspan=4, padx=5, sticky=E+W+S+N) 

To:

self.area = Text(self) self.area.grid(row=2, column=1, columnspan=2, rowspan=4, padx=5, sticky=E+W+S+N) 

This way your text box is set up as a class attribute that we can use.

Then use:

self.area.delete(1.0, "end") # to clear text box self.area.insert("end", your_output variable or string) # to insert content 
Sign up to request clarification or add additional context in comments.

6 Comments

Thanks @sierra Mountain. Let me try that.
Thanks @sierra Mountain. Let me try that.
@samuelkungu: Sorry I had to update my answer. Some typos and a little more explanation on what you need to do.
Thanks @sierra. I vote +1 because it has helped. Now the problem comes moving the value to print from one script to the script with GUI. Let me open another thread instead. Thanks again, I appreciate
@samuelkungu: In order to work with the text box in your Example class from outside of that class you will need to make sure the text box is set up as a class attribute with self. once that is done you can do something like app.area.insert("end", your_output variable or string). That should do the job.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.