从顶级控件类中的Frame类继承方法

时间:2018-11-09 23:43:44

标签: python tkinter

当前,我需要从toplevel类访问ttk.Frame类中的方法和实例变量;该程序将计算ttk.Frame类中的某些值,然后,我希望能够使用某些函数来计算ttk.Frametoplevel中的那些先前值。 / p>

class ReservoirDataFrame(ttk.Frame):
    def __init__(self, parent, controller):
        ttk.Frame.__init__(self, parent)
        self.controller = controller
        self.grid(row=0, column=0, sticky="nsew")
        self.grid_rowconfigure(0, weight=1)
        self.grid_columnconfigure(0, weight=1)
        self.main()
        ...
    def main(self):
        pass
    def fluid_properties_calculate(self):
        pass

所以,我想做的差不多是这样的:

class CurveIPR(tk.Toplevel, ReservoirDataFrame):
    def __init__(self, controller):
        tk.Toplevel.__init__(self, controller)
        ReservoirDataFrame.__init__(self, controller)
        self.controller = controller
        self.reservoir_data_frame = ReservoirDataFrame(self)
        self.minsize(600, 480)
        self.title("Curva de oferta IPR (Inflow performance relationship)")
        self.grid_rowconfigure(0, weight=1)
        self.grid_columnconfigure(0, weight=1)
        self.grab_set()
        self.main()

    def main(self):
        self.reservoir_data_frame.fluid_properties_calculate()

1 个答案:

答案 0 :(得分:0)

您需要一个沼泽标准对象,而不是继承对象。

class CurveIPR(tk.Toplevel):
    def __init__(self, controller):
        tk.Toplevel.__init__(self, controller)
        self.controller = controller
        self.reservoir_data_frame = ReservoirDataFrame(self, controller)
        # you really ought to grid it here, not in ReservoirDataFrame
        self.minsize(600, 480)
        self.title("Curva de oferta IPR (Inflow performance relationship)")
        self.grid_rowconfigure(0, weight=1)
        self.grid_columnconfigure(0, weight=1)
        self.grab_set()
        self.main()

    def main(self):
        self.reservoir_data_frame.fluid_properties_calculate()