割り当て用の Tkinter GUI を作成していますが、クラス メソッドへのアクセスで問題が発生しています。ここに貼り付けた最初のコードは、最上位のインターフェイス クラスです。コードのメイン関数は、「マスター」が Tk() のインスタンスであるこのクラスのインスタンスを作成します。
class PlotApp(object):
"""
Top level interface. Contains canvas and other widgets.
"""
def __init__(self, master):
# Initialise variables, world screen class and window features
master.wm_minsize(740, 480)
master.configure(bg = "gray80")
self.isFunctionDrawn = False
# Create objects
self.pointf = PointFrame(master)
self.canvas = Canvas(master, bg = "white", bd = 2, relief = SUNKEN,
highlightbackground = "gray80")
self.canvas.pack(expand = True, fill = BOTH, padx = 10, side = TOP)
self.functionf = FunctionFrame(master)
self.plotf = PlotFrame(master)
self.buttonf = ButtonFrame(master, self.canvas)
self.functionf
FunctionFrame
と呼ばれるメソッドを含む私のクラスのインスタンスですgetFunction()
。クラス インスタンスのボタンでこのメソッドにアクセスしたいのですが、そのButtonFrame
方法がわかりません。私はもう試した:
def testFunction(self):
self.parent.functionf.getFunction()
( whereparent
はmaster
コードの最初のビットの引数です) しかし、これはfunctionf
のオブジェクトとして呼び出しているようですTk()
。これは明らかに機能しません。これを回避する方法はありますか?