對不起標題。我不知道如何使它適合這個。
我正在抓取網站。大多數部分都已完成,現在我嘗試使用 TKinter 創建輸入欄位。使用 fileButton.py從 file 呼叫函式Bitkub_scrape.py。函式make_df()需要 valuefile_path才能作業。
我想在檔案中使用Entry欄位的輸入。Button.py它回傳:
FileNotFoundError: [Errno 2] No such file or directory: ''
其中''來自Bitkub_scrape.py。
這是我在“Bitkub_scrape.py”檔案中的功能代碼:
def make_df():
#for loop make list
for coin, chains, wdf in zip(coin_name_res, chain_name, fee_res):
#print("Coin name: {} Chain: {} Fee: {}".format(coin, chains, wdf))
#create dataframe
df=(pd.DataFrame({'coin_name': coin_name_res[0:100], 'chain_name': chain_name, 'withdrawal_fees':fee_res}))
#print(df)
file_path = ""
#csv
df.to_csv(file_path, index=False)
df_saved_file = pd.read_csv(file_path)
df_saved_file
driver.quit()
make_df()
這是我的Button.py檔案:
root = tkinter.Tk()
root.title('Bitkub Fee monitor')
root.geometry("500x500")
e = Entry(root, width=60)
e.pack()
def Bitkub():
from Bitkub_scrape import make_df
make_df()
file_path.append(e.get())
Bitkub_label = Label(root,text="Done, Check file name: Bitkub_fee.csv")
Bitkub_label.pack()
print(path)
Bitkub_button = Button(root,text="Get Bitkub Fee", command=Bitkub, height = 5, width = 60, bg="green")
Bitkub_button.pack()
root.mainloop()
uj5u.com熱心網友回復:
以下是如何實作我在評論中建議的內容——將Entry's 的內容傳遞給make_df()函式——這需要對兩個源檔案進行更改。請注意,以下內容未經測驗。
Button.py檔案更改:
from Bitkub_scrape import make_df
import tkinter as tk
root = tk.Tk()
root.title('Bitkub Fee monitor')
root.geometry("500x500")
e = tk.Entry(root, width=60)
e.pack()
def Bitkub():
make_df(e.get())
Bitkub_label = Label(root, text="Done, Check file name: Bitkub_fee.csv")
Bitkub_label.pack()
print(path)
Bitkub_button = tk.Button(root, text="Get Bitkub Fee", command=Bitkub, height=5, width=60,
bg="green")
Bitkub_button.pack()
root.mainloop()
Bitkub_scrape.py檔案更改:
import pandas as pd
def make_df(file_path):
for coin, chains, wdf in zip(coin_name_res, chain_name, fee_res):
#print("Coin name: {} Chain: {} Fee: {}".format(coin, chains, wdf))
# Create dataframe
df=(pd.DataFrame({'coin_name': coin_name_res[0:100], 'chain_name': chain_name,
'withdrawal_fees':fee_res}))
#print(df)
# Create CSV file
df.to_csv(file_path, index=False)
df_saved_file = pd.read_csv(file_path)
df_saved_file
driver.quit()
同時洗掉make_df()檔案末尾的呼叫。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/427108.html
