How can we write `DataFrame` object of `Pandas` using `filedialouge` in python `tkinter`.

```
file = filedialog.asksaveasfile(mode='w', defaultextension=".xlsx")
data.to_excel(file)

```

Whenever I try to write it it gives me error.

```
stat: path should be string, bytes, os.PathLike or integer, not _io.TextIOWrapper

```

I have been searching this error for hours, but the solutions are not working.