我正在尝试获取多个用户输入并将其存储在数据框中。我无法使用从do_stuff()定义中获得的数据框。请指出正确的方向。
import tkinter as tk
import tkinter.simpledialog as simpledialog
import pandas as pd
root = tk.Tk()
def do_stuff():
df2 = pd.DataFrame(columns=["Subsidiary", "Ownership"])
for _ in range(int(parts.get())):
dp = simpledialog.askstring("Data input window" , "Enter Subsidiary " )
st = simpledialog.askstring("Data input window" , "Ownership % {} " .format(dp))
df3 = pd.DataFrame(data=[[dp,st]],columns=["Subsidiary", "Ownership"])
df2 = pd.concat([df2,df3], axis=0)
return df2
tk.Label(root, text="Enter the number of Subsidiaries: ").grid(row=0, column=0)
parts = tk.Entry(root)
parts.grid(row=1, column=0)
def getInput(df2):
df2.head()
root.destroy()
tk.Button(root, text="Submit", command=do_stuff).grid(row=2, column=0)
tk.Button(root, text = "Close",command = getInput).grid(row = 2, column=1)
root.mainloop()