그래서 MyButton과 MyLabel이라는 하위 클래스가있는 Application 클래스가 있습니다. 응용 프로그램도 있습니다Super() python이 서브 클래스 tkinter에서 작동하지 않습니다.
self.backgroundcolor = 'orange'
self.textcolor = 'black'
하위 클래스 MyButton 및 MyLabel에서이 두 변수를 사용하고 싶습니다. 그래서,
class MyButton(Button):
def __init__(self, *args, **kwargs):
Button.__init__(self, *args, **kwargs)
self['bg'] = super(Application, self).backgroundcolor
self['fg'] = super(Application, self).textcolor
self['relief'] = FLAT
class MyLabel(Label):
def __init__(self, *args, **kwargs):
Label.__init__(self, *args, **kwargs)
self['fg'] = super(Application, self).textcolor
을 시도하지만
class Application(Frame):
global yearcal
def __init__(self, master=None):
Frame.__init__(self, master)
self.month = 5
self.year = 2014
self.color_clicked = 'lightskyblue'
now = datetime.datetime.now()
self.thisyear = now.year
self.thismonth = now.month
self.today = now.day
self.textcolor = 'purple'
self.bgcolor = 'gray'
self.today_color = 'palegreen1'
self.apt_color = 'light coral'
MORE STUFF HERE...
class MyButton(Button):
def __init__(self, *args, **kwargs):
Button.__init__(self, *args, **kwargs)
self['bg'] = super(Application, self).backgroundcolor
self['fg'] = super(Application, self).textcolor
self['relief'] = FLAT
class MyLabel(Label):
def __init__(self, *args, **kwargs):
Label.__init__(self, *args, **kwargs)
self['fg'] = super(Application, self).textcolor
'MyButton'은'Button'을 상속받습니다. 'Button'은'Application'에서 상속 받았습니까? –
버튼은 버튼을 만드는 미리 정의 된 tkinter 물건입니다. MyButton은 응용 프로그램의 변수 backgroundcolor 및 textcolor를 기반으로 자동으로 특성을 제공하는 '사용자 지정된'버전입니다. 미안하지만 더 자세한 설명은 할 수 없습니다. 내가 슈퍼 (응용 프로그램, 슈퍼 (버튼, 자기))와 같은 것을해야한다고 말하고 있습니까? 어쩌면 내가 그것을 시도해야합니다. – Kevin
아니요, 작동하지 않았습니다. Button()이 tkinter의 일부이기 때문일 수 있습니다. – Kevin