samedi 28 mars 2015

How to output text result in python GUI tinker?

Someone please help me, I'm trying to used Python 2.7 Tkinker GUI to display the result of 'file.py path' in the text widget but it output in the PyCharm not the GUI text. Secondly is it possible to used the 'path=f' outside the 'def callback().



from Tkinter import *
from tkFileDialog import *
import os

#browse files
def callback():
f = askopenfilename()
path.set(f)
r = os.popen('pdfid.py'+' '+f).read()
print r
#Function
def pdfid():
result = os.popen('pdfid.py'+' '+f).read()
return result
def pdfparser():
result = os.popen('pdf-parser.py'+' '+f).read()
return result
#Run Function
def runSelectedItems():
if v1.get() == 1:
print'Pdfid = True'
else:
print'Pdfid = False'
if v2.get() == 1:
print'Pdf-parser = True'
else:
print'Pdf-parser = False'
#Tools Checkbox
def checkbox():
cf = LabelFrame(root, text="Tools")
cf.pack(side=TOP, anchor=N)
left = Label(cf)
v1 = IntVar()
v2 = IntVar()
C1 = Checkbutton(cf, text = "Tool1", variable = v1, command = pdfid)
C2 = Checkbutton(cf, text ="Tool2", variable = v2, command = pdfparser)
C1.pack(side=LEFT, anchor=W)
C2.pack(side=LEFT, anchor=W)
#Button
def button():
b = Button(root, text='Open', command=callback)
l = Label(root, text='File Path: ')
e = Entry(root, textvariable=path, width=50)
r = Button(root, text='Run', command=runSelectedItems)
b.pack(padx=5, pady=0, side=LEFT, anchor=N)
l.pack(padx=5, pady=0, side=LEFT, anchor=N)
e.pack(padx=5, pady=0, side=LEFT, anchor=N)
r.pack(padx=5, pady=0, side=RIGHT, anchor=N)
#main
root = Tk()
path = StringVar()
result = StringVar()
label=LabelFrame(root, text="Output")
label.pack(side=BOTTOM, anchor=W, fill=BOTH, expand=YES)
text = Text(label)
text.pack(fill=BOTH, expand=YES)
button()
checkbox()
root.mainloop()




Aucun commentaire:

Enregistrer un commentaire