과제를위한 Tkinter GUI를 작성 중이며 클래스 메소드에 액세스 할 때 몇 가지 문제가 발생했습니다. 여기에 붙여 넣은 코드의 첫 번째 비트는 최상위 인터페이스 클래스입니다. 코드의 주요 기능은 "master"가 Tk() 인스턴스이고이 클래스의 인스턴스를 만듭니다.Python 2.7의 다른 클래스에서 클래스 메서드에 액세스
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
는 getFunction()
라는 메소드를 포함 내 FunctionFrame
클래스의 인스턴스입니다. 이 메서드에 액세스하려면 ButtonFrame
클래스 인스턴스의 단추를 원하지만이 작업을 수행하는 방법을 모르겠습니다. 나는 시도했다 :
def testFunction(self):
self.parent.functionf.getFunction()
(parent
코드의 첫 번째 비트에서 master
인수 곳이다) 그러나 이것은 분명히 작동하지 않을 Tk()
의 객체로 functionf
를 호출하는 것으로 보인다. 이 주위에 어떤 방법이 있습니까?
감사합니다 힙 언더런, 트릭 완료되었습니다. – Drizzlydayz