I am trying to make a little converter from pdf to word in python, so I have two functions one for converting the file and one to save the file. I wonder how to define a variable in both functions: here what I wrote, docx_file
is giving me error not defined in the convert function.
def convert():
try:
pdf = fileEntry.get()
cv = Converter(pdf)
cv.convert(docx_file, start=0, end=None)
cv.close()
if docx_file is None:
return
except FileNotFoundError:
fileEntry.delete(0,END)
fileEntry.config(fg="red")
fileEntry.insert(0,"Please select a pdf file first")
except:
pass
def save2word():
docx_file = asksaveasfile(mode='w',defaultextension=".docx", filetypes=[("word file","*.docx"), ("text file","*.txt")])
docx_file.write()
docx_file.close()
if docx_file is None:
return
print("saved")
fileEntry.delete(0,END)
fileEntry.insert(0,"pdf Extracted and Saved...")