我正在将TKinter用于显示UI,并要求导入CSV和TXT 2个文件。
打开文件后,path
应该保存在f1和f2上,然后传递到外部* .py脚本os.system(*.py f1 f2)
内部成功执行并读取了熊猫DF和txt文件。当我想在变量上存储路径然后在os.system
我设置了print()
用于检查路径。
# tk Frame for request files
import sys
import os
import tkinter as tk
import pandas as pd
from tkinter import filedialog
import csv
root= tk.Tk()
canvas1 = tk.Canvas(root, width = 400, height = 400, bg = 'lightsteelblue2', relief = 'raised')
canvas1.pack()
f1 = ''
f2 = ''
def importCSV ():
global df
fin = filedialog.askopenfilename(title = "Select file",filetypes = (("csv files","*.csv"),("all files","*.*")))
print(fin)
f1 = fin
df = pd.read_csv(fin)
def importTXT ():
global df
fin2 = filedialog.askopenfilename(title = "Select file",filetypes = (("txt files","*.txt"),("all files","*.*")))
print(fin2)
f2 = fin2
with open(fin2) as f1:
for line in f1:
line.strip()
print(f1 + f2)
# prepare values to pass to os.system()
# pass = 'python Eje_SysArg.py ' + f1 + ' ' + f2
def CrearCom ():
global df
#os.system(pass)
os.system('python Eje_SysArg.py f1 f2')
ImportAsButton_CSV = tk.Button(text='Import Parameters "CSV"', command=importCSV, bg='green', fg='white', font=('helvetica', 12, 'bold'))
canvas1.create_window(200, 100, window=ImportAsButton_CSV)
ImportAsButton_TXT = tk.Button(text='Import command "TXT"', command=importTXT, bg='green', fg='white', font=('helvetica', 12, 'bold'))
canvas1.create_window(200, 200, window=ImportAsButton_TXT)
CreateAsButton = tk.Button(text='Create Script', command=CrearCom, bg='green', fg='white', font=('helvetica', 12, 'bold'))
canvas1.create_window(200, 300, window=CreateAsButton)
root.mainloop()
GUI的当前结果是:
D:\python\Multicomando>python GUI_v1.py
D:/python/Multicomando/SCCPGT.csv
D:/python/Multicomando/comando.txt
Eje_SysArg.py
fin
fin2
预期结果为('python Eje_SysArg.py D:/python/Multicomando/SCCPGT.csv D:/python/Multicomando/comando.txt')