результат открытия файла в TKINTER передать в функцию и експортировать в отдельный файл

Помогите пожалуйста организовать функцию вывода информации из листбокса в отдельный файл - загрузить прочитанный файл и выведенный в листбокс в отельный файл xlsx вот код

from tkinter import *
from tkinter import filedialog



def onBtnDelete():
    listbox.delete(0,END)
    return


def onBtnAdd():
    filename = filedialog.askopenfilename()
    with open(filename, 'r+', encoding='windows-1251') as input_file:
        for line in input_file:
            word = 'Контракт'
            if word in line != -1:
                listbox.insert(END, line)

            word2 = 'Тарифний Пакет'
            if word2 in line != -1:
                listbox.insert(END, line)

            word3 = 'ВАРТІСТЬ ПАКЕТА/ЩОМІСЯЧНА ПЛАТА'
            if word3 in line != -1:
                listbox.insert(END, line[0:32] + line[40:70])



def export_to_file():
    with open('list000.xlsx', 'w', encoding='utf-8') as f:
        f.write(onBtnAdd())



root = Tk()
root.update()
root.geometry("600x1200+600-300")
root.title("Reddit Downloader")

listbox = Listbox(root, width=60, height=30, font="12")
# listbox.bind('<<ListboxSelect>>', onItemSelect)
listbox.pack(pady=100)



buttonFrame = Frame(root)
buttonFrame.pack(pady=5)
btnAdd = Button(buttonFrame, text="Add", command=onBtnAdd)
btnAdd.pack(padx=10, side=LEFT)
btnDelete = Button(buttonFrame, text="Delete", command=onBtnDelete)
btnDelete.pack(padx=10, side=LEFT)
btnExport = Button(buttonFrame, text="Export", command=export_to_file)
btnExport.pack(padx=10, side=LEFT)

root.mainloop()

Ответы (0 шт):