我正在尝试创建一个小的GUI以将Parquet转换为XLSX文件。在我的代码中,我当前正在使用tkinter创建一个GUI,然后使用一个函数将Parquet转换为XLSX。
尽管我运行下面的代码,但仍然收到错误消息,“ myfunc()缺少3个必需的位置参数:'txt_file','txt_name'和'txt_dir'”,为什么不分配它们? >
import os
import pandas as pd
from tkinter import *
import pyarrow
import shutil
from pathlib import Path
window = Tk()
window.title("Convertor")
#Sets the size of the window
window.geometry('550x200')
#Adds a header to the window and configures the size
lbl = Label(window, text="Convert Parquet to CSV", font=("Arial Bold", 18))
#Configures where the label message will appear
lbl.grid(column=0, row=0)
#asks for parquet file
lbl2 = Label(window, text="Where is the parquet file currently located?", font=("Arial", 12))
lbl2.grid(column=0, row=1)
#adds a field for an input text message
txt_file = Entry(window,width = 30)
txt_file.grid(column=1, row=1)
#asks for name of xlsx file
lbl3 = Label(window, text="What would you like to call the new xlsx file?", font=("Arial", 12))
lbl3.grid(column=0, row=2)
txt_name = Entry(window,width = 30)
txt_name.grid(column=1, row=2)
#asks where you want to put the new xlsx file
lbl3 = Label(window, text="Where would you like to ouput the xlsx file?", font=("Arial", 12))
lbl3.grid(column=0, row=3)
txt_dir = Entry(window,width = 30)
txt_dir.grid(column=1, row=3)
def myfunc(txt_file, txt_name, txt_dir):
file = txt_file
df1 = pd.read_parquet(file)
df = df1.append(df1, ignore_index=True)
dirout = txt_dir
name = txt_name
cfile = os.path.join(dirout, name + "." + "xlsx")
df.to_excel(cfile)
#Adding a button
btn = Button(window, text="Convert", command=myfunc)
btn.grid(column=1, row = 4)
#The mainloop causes the window to remain open until someone interacts with it
window.mainloop()
我正在尝试创建一个小的GUI以将Parquet转换为XLSX文件。在我的代码中,我当前正在使用tkinter创建一个GUI,然后使用一个函数将Parquet转换为XLSX。当我运行时...
而不是将值传递到函数中,而是让函数从UI检索值。在您的情况下,您要将小部件保存在全局变量中,这使得此操作很容易。