Search code examples
pythontkinterconvertapi

Convertapi module launch multiple tkinter instances when called


I'm using the module convertapi to merge files in a tkinter application in Python3.8. When I have some tkinter window in my code, if convertapi.convert('merge', {'Files': input_files}) is called, multiple instances of the tkinter window open. My script:

from tkinter import *
import convertapi

input_files = ["file1.pdf", "file2.pdf", "file3.pdf"]
output_file = "mergedFile.pdf"

def mergePDFs(input_files, output_file):
    convertapi.api_secret = 'my-api-secret'
    result = convertapi.convert('merge', {'Files': input_files})
    result.file.save(output_file)


root = Tk()
Button(root, text="Merge", command=lambda: mergePDFs(input_files, output_file)).pack()
root.mainloop()

enter image description here

It's a very weird behavior since even when I call the function in the console with the tkinter window closed beforehand, multiple windows still open up. I'm guessing there is some kind of incompatibility between the two modules but I can't be sure. If it can help, there are 10 more instances of the tkinter window that open up when the funstion is called.


Solution

  • Problem solved! Solution can be found on github here.