2013-08-05 3 views
1

나는 그 이유가 내가 가진 자기와 비슷하다고 생각할 것입니다. 왜 거기에 주인이 있습니까? 또한, 왜 때로는 주인이며 때로는 주인이 아닌가?파이썬의 init 함수에서 master와 none의 목적은 무엇입니까?

예컨대 Tkinter를 8.5 기준에서

class Application(tk.Frame): 
    def __init__(self, master=None): 
     tk.Frame.__init__(self, master) 
     self.grid() 
     self.createWidgets() 

: 존 W. 선원에 의해 파이썬을위한 GUI. 또한, doc은 python3을 사용하는 동안 python2를 사용합니다. 나는 주인이 필요합니까? 더 많은 문제 master 뒤에 사용자 정의 arg을 추가하려고 시도했는데 기본 이후에 non-default arg을 추가 할 수 없다고 말하면 어떻게 수정해야합니까? 기본 arg 자체가 먼저 있어야하지 않습니까?

def __init__(self, master=None,inputDict): 
    tk.Frame.__init__(self, master) 
    self.grid(sticky=tk.N+tk.S+tk.E+tk.W) 
    self.createWidgets() 
def createWidgets(self,inputDict): 
    top=self.winfo_toplevel() 
    top.rowconfigure(0, weight=1) 
    top.columnconfigure(0, weight=1) 
    self.rowconfigure(0, weight=1) 
    self.columnconfigure(0, weight=1) 
tempDict = {} 
for k,v in inputDict.items(): 
     if 1<=v[0]<=3: 
      tempDict[k] = static_keys(*v[1:]) 
     elif v[0] ==4: 
      tempDict[k] = dynamic_keys(*v[1:]) 
     elif v[0]==5: 
      tempDict[k] = key_labels(*v[1:]) 
return tempDict 

답변

1

당신 Application 클래스는 tk.Frame의 서브 클래스입니다. master은 상위 위젯이며 초기화 될 때 Application 클래스의 새 인스턴스에 전달되는 선택적 매개 변수 (기본값은 none)입니다.

Take a look here for more info.

+0

상위 항목이라고해야합니다. 나는 SO가 허락하자마자 제외 할 것입니다. – fozbstuios

+0

동의합니다 ...하지만 같은 개념으로 작동합니다 ... –

+0

또한 init func을 호출 할 때 def가 0이면 뒤에 master가 필요합니다. 자기는 어쩌고? – fozbstuios

관련 문제