Tkinterを使用してPython2.7.3でグラフィカルフロントエンドをプログラミングしています。メインメニュー(例ではA)とウィンドウ(B)があります。Aにはリストボックスが含まれ、BはAのリストボックスのコンテンツを必要とする何かを実行しています。Bが作業を終了した後、A(doSomething)というメソッドが必要です。私の簡略化されたコードは次のようになります。
#!/usr/bin/env python
import Tkinter as tk
class A(object):
def __init__(self, root):
self.__mainMenu = root
self.__LB = tk.Listbox(self.__mainMenu)
self.__LB.pack()
self.__LB.insert(tk.END, "foo")
b = B(self.__mainMenu, self.__LB)
def doSomething(self):
print "Ham and spam!"
class B(object):
def __init__(self, mainMenu, LB):
self.__mainMenu = mainMenu
self.__LB = LB
print self.__LB.get(0)
self.__mainMenu.doSomething()
def main():
root = tk.Tk()
gui = A(root)
root.mainloop()
main()
次の出力が生成されます。
$ ./myTest.py
foo
Traceback (most recent call last):
File "./myTest.py", line 29, in <module>
main()
File "./myTest.py", line 26, in main
gui = A(root)
File "./myTest.py", line 11, in __init__
b = B(self.__mainMenu, self.__LB)
File "./myTest.py", line 21, in __init__
self.__mainMenu.doSomething()
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1767, in __getattr__
return getattr(self.tk, attr)
AttributeError: doSomething
このエラーはどこから発生しますか?エラー出力が非常に悪いのはなぜですか?