今回はtkinterからcsvファイルを指定し、
数値を読み込み、tkinter上にデータを出力するアプリを作成しました。
以下が全体のソースコードです。
qiita.py
import tkinter as tk
import tkinter.filedialog as fl
def get():
#ファイルパスをマウスで選ぶ
#ユーザー名にお使いのPCの名前を入れる
filetype=[("all file","*")]
path=fl.askopenfilename(initialdir="C:\\Users\\ユーザー名\\デスクトップ",filetypes=filetype)
#csvファイルの読み込み
f = open(path,"r")
text = []
for i in f.readlines():
i=i.strip()
i=i.split("\n")
if i == ['']:
pass
else:
text.append(i)
line = text[0][0]
line_split = line.split(',')
line_split = list(map(int, line_split))
# ラベル
lbl = tk.Label(text='数値')
lbl.place(x=150, y=70)
# csvファイルの数値を出力する
txt = tk.Entry(width=50)
txt.place(x=200, y=70)
txt.insert(tk.END,f"{line_split}")
##main処理
root=tk.Tk()
root.title("csvファイルの読み込み&出力")
root.geometry('600x400')
button=tk.Button(text="csvファイル開く",command=get)
button.pack()
root.mainloop()