简体   繁体   中英

Saving data from multiple text files to a single file

I was trying to open multiple files using tkinter . I want to see the contents in these multiple files and put these text files to a single file but on different cells, so that i can treat all the data together. I was not able to find ant tutorial to understand more about tkinter. Can anyone suggest me an idea on how to see the contents in these files?

I have an idea on how to do this on matlab, can anyone suggest a way to do the same in python?

Matlab code:

[filename,pathname] = uigetfile('*.txt','MultiSelect','on');
data = cell(1)

Python code:

import tkinter as tk
from tkinter import filedialog

root = tk.Tk()
filez = filedialog.askopenfilenames(parent=root,title='Choose a file')
print (root.tk.splitlist(filez))

Example of how you might do it. If your files ar bigger you might want to use ScrolledText instead. I have not included buttons or logic or laying out of more than two files side by side, or how to combine them. But then again, your question was kind of broad.

import tkinter as tk
from tkinter import filedialog

# Some test data
text = """lid,loan_amount,currency,sector
653051,300.0,Changed,Food
53,575.0,PKR,Trns
653068,150.0,INR,Trns
653063,200.0,PKR,Arts
653084,400.0,PKR,Food
653067,200.0,INR,Agri
653078,400.0,PKR,Serv
653082,475.0,PKR,Manu
653048,625.0,PKR,Food"""

root = tk.Tk()
main = tk.Frame(root, padx=10, pady=10)
root.resizable(width=False, height=False)
main.pack()

text1 = tk.Text(main, width=40, height=20, padx=10, pady=5)
text1.pack(side='left')
text2 = tk.Text(main, width=40, height=20, padx=10, pady=5)
text2.pack(side='left', padx=(10,0))

# Put filedialog and open files here

text1.insert('end', text)
text2.insert('end', text)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM