单击主窗口中的按钮后,我想在其他类中运行函数。我应该如何将值 [id_entry] 从类 [StartingPage] 中的数据输入传递到第二类 [Graph] 中的函数 [read_data]。单击“分析费用”按钮后,我想传递值并运行功能。可能吗?
class MainWindow(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
tk.Tk.iconbitmap(self)
tk.Tk.wm_title(self, 'Data analyser')
window = tk.Frame(self)
window.pack(side='top', fill='both', expand = True)
window.grid_rowconfigure(0, weight=1)
window.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartingPage, Graph):
frame = F(window, self)
self.frames[F] = frame
frame.grid(row = 0, column = 0, sticky = 'nsew')
self.show_gui(StartingPage)
def show_gui(self, window):
frame = self.frames[window]
frame.tkraise()
class StartingPage(tk.Frame):
def __init__(self, parent, window):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text = 'Upload document')
label.pack(pady = 10, padx = 10)
button1 = ttk.Button(self, text = 'Upload XLS file',
command=lambda: self.open_file())
button1.pack()
button2 = ttk.Button(self, text = 'Analyse expense',
command=lambda: window.show_gui(Graph))
button2.pack()
id_entry = ttk.Entry(self)
id_entry.pack()
def get_string(self):
return self.id_entry.get()
def open_file(self):
file = askopenfile(mode='r', filetypes=[('excel files', '*.xlsx')])
export_do_SQL.export_to_sql(file.name)
class Graph(tk.Frame):
def __init__(self, parent, window):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text = 'Expense analyser')
label.pack(pady = 10, padx = 10)
button1 = ttk.Button(self, text = 'Return',
command=lambda: window.show_gui(StartingPage))
button1.pack()
id_element = read_data(DATA FROM INPUT)