【发布时间】:2013-05-06 09:30:56
【问题描述】:
http://effbot.org/tkinterbook/tkinter-dialog-windows.htm 有一个例子 还有一件事我不明白:
class Dialog(Toplevel):
...
self.result = None
...
class MyDialog(Dialog):
def apply(self):
first = int(self.e1.get())
second = int(self.e2.get())
self.result = first, second
d = MyDialog(root)
print d.result
他们通过引用d.result 在apply 方法中访问self.result。
我尝试用我自己的简单示例来重构它:
class Mother(object):
def __init__(self):
self.result = None
def apply(self):
pass
class Class(Mother):
def apply(self):
self.result = "hello"
d = Class()
print d.result
print d.result 的输出是 None 而不是 "hello"
请帮忙。
【问题讨论】:
标签: python class variables methods