我在一个“子屏幕”中有一个组合框,我正在使用组合框值过滤原始数据框,但我无法使用生成的数据框在树视图函数或其他位置显示它。我不知道如何调用这个函数来在其他地方使用它。
这是我的子屏幕:
class MantPrev(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
super().__init__(parent)
self.tabla_data()
self.loc_combo()
def loc_combo(self):
conexion = CNX()
CombValue1 = ComboLoc()
calc_sinv = pd.DataFrame()
sql = " SELECT etc' "
try:
conexion.cursor.execute(sql)
calc_sinv = conexion.cursor.fetchall()
conexion.cerrar()
except:
col_name = ([desc[5] for desc in conexion.cursor.description])
self.algo_var = tk.StringVar()
self.algo_combo1 = ttk.Combobox(self, width=30)
self.algo_combo1['values'] = ComboLoc()
self.algo_combo1.set('')
self.algo_combo1.place(x=50, y=40) # grid(row=32, column=2, padx=0, pady=1)
self.algo_combo1.bind("<<ComboboxSelected>>", self.location)
self.algo_combo1.delete("0", tk.END)
def location(self, event):
df1 = CL001()
loc_selected = self.algo_combo1.get()
self.df2 = df1[(df1.LOCATION == loc_selected)]
return self.df2
我设法打印 self.df2 但我无法在不同的功能中使用它
def tabla_data(self):
self.Sele = location()#####is not working# .to_numpy().tolist()
self.tablaO = ttk.Treeview(self,
columns=('a', 'b', 'c', 'd'), height='20',
selectmode=tk.NONE)
self.tablaO.grid(row=20, column=0, columnspan=3, pady=4)
self.tablaO.place(width=1000, height=300)
self.tablaO.place(relx=0.5, rely=0.5, anchor=CENTER)
self.tablaO.heading('#0', text='Localización')
self.tablaO.heading('#1', text='Descripción_MP')
self.tablaO.heading('#2', text='Fecha_Estatus_OT')
self.tablaO.heading('#3', text='Estatus_OT')
self.tablaO.heading('#4', text='Elemento')
self.tablaO.column('#0', width=140)
self.tablaO.column('#1', width=140)
self.tablaO.column('#2', width=140)
self.tablaO.column('#3', width=140)
self.tablaO.column('#4', width=140)
self.tablaO.delete(*self.tablaO.get_children()) # Delete all times inside the treeview
for p in self.Sele:
self.tablaO.insert('', 0, text=p[3],
values=(p[11], p[1], p[2], p[13]))
labl_1 = Label(self, text="Localización", width=24, font=("bold", 10))
labl_1.place(x=50, y=10)
labl_11 = Label(self, text="Elemento", width=24, font=("bold", 10))
labl_11.place(x=300, y=10)
labl_2 = Label(self, text="Fecha Inicio MP", width=20, font=("bold", 10))
labl_2.place(x=550, y=10)
labl_3 = Label(self, text="Fecha Fin MP", width=20, font=("bold", 10))
labl_3.place(x=750, y=10) # (x=ancho, y=altura )
if __name__ == "__main__":
要从同一个类中调用方法,请在其前面加上
self
,例如:
self.Sele = self.location()